node.js中的Date对象有一些奇怪的行为

Date Object in node.js has some weird behaviour

本文关键字:中的 js Date 对象 node      更新时间:2023-09-26

我用NODE测试了一段时间,我经历了JS Date()对象的奇怪行为。getDay()getMonth()函数返回错误结果。我认为我在应用的某个地方搞砸了,但我也在主机上进行了测试,仍然是相同的行为。下面是控制台的日志:

$ node
> var currentDate = new Date();
undefined
> currentDate
Wed Jun 19 2013 13:54:20 GMT+0200 (CEST)
> currentDate.getDay()
3
> currentDate.getMonth()
5

它似乎偏离了'一点'。

我不知道是怎么回事,网上搜索也帮不了我。

getDay方法返回星期几,因此3表示星期三。

getMonth方法返回从0开始的月份,因此5表示6月。