正如 w3schools 所说,Date.parse() 返回“日期字符串与 1970 年 1 月 1 日午夜之间的毫秒数。”
这意味着
如果我写 Date.parse("January 1, 1970 00:00:00"),它应该给我答案 0。
如果我写 Date.parse("January 1, 1970 00:00:05"),它应该给我答案 5000.. 但我得到的是 -14395000... 为什么是那?
最佳答案
您没有指定时区,因此 January 1, 1970 00:00:00
是您所在时区的时间偏移量(或者更准确地说是浏览器为您选择的时区)。返回的毫秒数是相对于 UTC 的。
The Date.parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
[...] If you do not specify a time zone, the local time zone is assumed. GMT and UTC are considered equivalent. The local time zone is used to interpret arguments in RFC2822 Section 3.3 format that do not contain time zone information. [...]
关于javascript - Javascript 毫秒问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23010569/