0

I was trying to understand if it's safe to execute (new Date()).getTime() in different timezones.

By reading this question, it seems that it actually is time zone independent (assuming that the time on the machine where the script is executed was set correctly).

However, since it's the number of milliseconds since 1/1/1970, if we execute the same script from the next time zone, why it doesn't differ by 3600*1000 (the number of milliseconds in one hour)?

4

2 回答 2

3

你指的是UTC。它始终基于 GMT 时间,因此无论您从何处执行代码,GMT 时间都是一致的。

于 2018-07-23T08:28:46.257 回答
2

因为它使用
来自MDN 的UTC

getTime() 始终使用 UTC 表示时间。例如,一个时区的客户端浏览器,getTime() 将与任何其他时区的客户端浏览器相同。

于 2018-07-23T08:28:58.147 回答