为什么我不能通过点击+来增加日期?
+
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); });
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);
});
个字符
py49o6xq1#
将dayLength添加到当前日期new Date()。您应该将其添加到current变量。
dayLength
new Date()
current
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); });
current = new Date(current.getTime() + dayLength);
个字符请注意,我还将valueOf更改为getTime,因为对于docs,通常不会在用户代码中调用valueOf。
valueOf
getTime
1条答案
按热度按时间py49o6xq1#
将
dayLength
添加到当前日期new Date()
。您应该将其添加到current
变量。个字符
请注意,我还将
valueOf
更改为getTime
,因为对于docs,通常不会在用户代码中调用valueOf
。