【发布时间】:2019-12-24 17:32:19
【问题描述】:
我在 node.js v11.6.0 中运行它
const now = new Date(Date.now());
let date = now;
date.setFullYear(date.getFullYear() - 1);
let str = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
while(!data[str]){
date = date.setDate(date.getDate() - 1);
str = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
}
得到:
trail.js:15 str = date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate();
TypeError: date.getFullYear is not a function
在 while 循环中 date.setDate() 有效,但 date.getFullYear() 突然不是一个函数。
【问题讨论】:
-
永远值得checking the documentation...
-
new Date(Date.now())将产生与new Date()相同的结果。
标签: javascript node.js date