有人可以帮助我理解为什么这不起作用?
document.write('messing with the dates: <br>')
var nowDate = new Date();
var currentDay = nowDate.getDate();
nowDate.setDate(currentDay + 1);
document.write('if it\'s not inside a variable, it\'s nice and tidy: ' + nowDate.getDate() + '<br>');
var tomorrow = (nowDate.setDate(currentDay + 1));
document.write('but as soon as I put it inside a var, it becomes terrible: ' + tomorrow);
document.write('and this is not even working' + tomorrow.getDate());
最佳答案
setDate
执行两件事,更改日期对象本身,并返回结果日期自 1970 年 1 月 1 日 00:00:00 UTC 以来的毫秒数。
这是您明天
收到的号码
我想你应该像这样使用它来实现你想要做的事情:
var tomorrow = new Date((nowDate.setDate(currentDay + 1)))
关于javascript - 尝试将 getDate() 包含在 var 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33986391/