【发布时间】:2017-03-07 16:17:28
【问题描述】:
谁能用破折号分隔日期来解释以下行为?
console.log(new Date('2015/03/03'));
Tue Mar 03 2015 00:00:00 GMT+0000 (GMT Standard Time)
console.log(new Date('2015-03-03'));
Tue Mar 03 2015 00:00:00 GMT+0000 (GMT Standard Time)
console.log(new Date('2015/04/03'));
Fri Apr 03 2015 00:00:00 GMT+0100 (GMT Daylight Time)
console.log(new Date('2015-04-03'));
Fri Apr 03 2015 01:00:00 GMT+0100 (GMT Daylight Time) // This is the weird one
注意:我在英国,所以冬天是 GMT+0,“夏天”是 GMT+1。
注意 2:我读过我应该使用 '/' 作为分隔符,特别是因为 IE11 不这样做,但我想知道这在 Chrome 中怎么会发生?
注意 3:在 NodeJS 中它变得更加奇怪。
console.log(new Date('2015/03/03'));
2015-03-03T00:00:00.000Z
console.log(new Date('2015-03-03'));
2015-03-03T00:00:00.000Z
console.log(new Date('2015/04/03'));
2015-04-02T23:00:00.000Z //This is the weird one this time
console.log(new Date('2015-04-03'));
2015-04-03T00:00:00.000Z
【问题讨论】:
-
8601 是一条真正的道路。 relevant xkcd
-
@cloudworks ... ECMAScript 没有完全遵循。 :(
-
谢谢。重复的链接确实与答案相关。
标签: javascript node.js date timezone