我有这些行代码:
const start = new Date();
const end = start.setDate(start.getDate() + 7);
console.log(start, new Date(), end);
end
设置正确,提前一周。
start
时间(即当前时间)竟然等于end
时间?!
我从来没有将start
分配给new Date
以外的任何东西!!
为什么和如何解决这个问题?
setDate函数更改对象日期。在你的例子中,它改变了开头。
const start = new Date();
const end = new Date();
end.setDate(start.getDate() + 7);
console.log(start, new Date(), end);
Const在这里也没有意义