0
任何人都可以用短劃線日期解釋以下行爲嗎?Javascript上有趣的怪癖
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是一個真實路徑。 [相關xkcd](https://xkcd.com/1179/) – cloudworks
@cloudworks ... ECMAScript沒有完全遵循。 :( –
謝謝。重複鏈接是真正相關的答案。 – Chexpir