let todaySeconds = Date.now();
//1591238661657
let todayDate = new Date(todaySeconds);
//Thu Jun 04 2020 05:44:21 GMT+0300 (Eastern European Summer Time
//3600 * 24 = 86400s in a day
console.log(new Date(todaySeconds + 86400));
//Thu Jun 04 2020 05:45:48 GMT+0300 (Eastern European Summer Time)
为什么上面不是2020年06月05日?
JavaScript的时间戳以毫秒为单位,而不是以秒为单位。你必须添加 24 * 60 * 60 * 1000
.
let todayMillis = Date.now();
let todayDate = new Date(todayMillis);
console.log(todayDate);
console.log(new Date(todayMillis + (24 * 60 * 60 * 1000)));
你假设你的工作是以秒为单位。你是在用毫秒工作。请看 https:/developer.mozilla.orgen-USdocsWebJavaScriptReferenceGlobal_ObjectsDatenow。
The static Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.