如何阻止代码在特定日期运行

时间:2016-05-09 08:37:14

标签: javascript date

我想阻止我的代码的某个特定部分在其 29th of may 时运行。有人可以通过jQueryJavaScript帮助我解决此问题。

3 个答案:

答案 0 :(得分:0)

var diff = ( new Date('2016/05/29 00:00:01') - new Date() );
if( diff > 0 ){
   /*   Your Code here  */
}

如果差异为负,则今天的日期超过5月29日

答案 1 :(得分:0)

您可以尝试这样的事情,

var CurrentDate = new Date();
var YourSelectedDate = new Date(2016, 04, 29, 10, 15); //Here it is 29th may 2016

    if(CurrentDate > YourSelectedDate ){
        //CurrentDate is more than YourSelectedDate 
       // Display warning message or whatever you want to display.
    }
    else{
        //YourSelectedDate is more than CurrentDate
        //put your code in this part.
    }

答案 2 :(得分:0)

这是一个例子

您可以使用Date objects;

这是你可以开始的东西,有更好的方法来做到这一点,因为你没有显示任何代码我假设你不知道日期对象,有乐趣编码!

0.015718
Woke up
0.015814
Woke up
0.015942
Woke up
0.016107
Woke up
0.01625
Woke up
0.016363

示例II

  final PlanetHolder finalHolder = holder;

  //set the check box if its previously checked
  if(p.isCheckBoxchecked)
  {
   finalHolder.chkBox.setChecked(true);
  }


  holder.chkBox.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          if (finalHolder.chkBox.isChecked()) {
              finalHolder.edit.setVisibility(View.VISIBLE);
              finalHolder.edit.setEnabled(true);
              SharedPreferences preferences = getContext().getSharedPreferences("MaterialTabs", android.content.Context.MODE_PRIVATE);
             /* SharedPreferences.Editor editor = preferences.edit();
              editor.putBoolean("showActivity", finalHolder.chkBox.isChecked());
              editor.commit();*/
             // boolean value= true;
              SharedPreferences.Editor mEditor = preferences .edit();
              mEditor.putBoolean("CheckBox_Value", finalHolder.chkBox.isChecked());
              mEditor.commit();

              finalHolder.edit.addTextChangedListener(new TextWatcher() {
                  @Override
                  public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                  }

                  @Override
                  public void onTextChanged(CharSequence s, int start, int before, int count) {
                  }

                  @Override
                  public void afterTextChanged(Editable s) {

                  //set the item been checked
                  p.setCheckBoxCheck(true);


                  }
              });
          } else {
              finalHolder.edit.setVisibility(View.GONE);
              finalHolder.edit.setEnabled(false);
              finalHolder.edit.setText(null);

          }

      }
  });