无法在Js日期库中增加日期

时间:2016-10-29 06:19:47

标签: javascript jquery

您能告诉我为什么我无法点击onCreate() { ... getNewsItems(new NewsItemsListener() { void onFetched(ArrayList<NewsItems> items) { // Do whatever you want to do with your news items } }); } public void getNewsItems(final NewsItemsListener listener) new AsyncTask<Void, Void, ArrayList<NewsItems>>() { @Override protected ArrayList<NewsItems> doInBackground(Void... params) { ArrayList<NewsItems> response = whatEverMethodGetsMeNetworkCallResponse(); return response; } @Override protected void onPostExecute(ArrayList<NewsItems> response) { super.onPostExecute(response); listener.onFetched(response); } }.execute(); } public interface NewsItemsListener { void onFetched(ArrayList<NewsItems> items); }

来增加这一天的时间

+
  var dayLength = 1000*3600*24;
  var current = new Date();
  console.log(current);
  $('button').on('click', function(){
    var a = new Date((new Date()).valueOf() + dayLength);
    console.log(a);
   });

1 个答案:

答案 0 :(得分:1)

您将dayLength添加到new Date()这是当前日期。您应该将其添加到current变量。

&#13;
&#13;
  var dayLength = 1000*3600*24;
  var current = new Date();
  console.log(current);

  $('button').on('click', function(){
    current = new Date(current.getTime() + dayLength);
    console.log(current);
   });
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="btn btn-default">+</button>
&#13;
&#13;
&#13;

请注意,我还将valueOf更改为getTime,因为每docs,通常不会在用户代码中调用valueOf