Date.now() 是自纪元以来的本地毫秒数,还是自纪元以来的毫秒数(UTC 时间)
Is Date.now() in local milliseconds since epoch, or milliseconds since epoch in UTC time
我的印象是 Date.now()
是自我们 local 时区的纪元以来的毫秒数。如果是这样的话,我怎样才能得到自 UTC 时间纪元以来的毫秒数?我猜这将是很长的路要走:
new Date(new Date().toUTCString()).getTime()
有没有更快的方法?
Date.now()
and new Date().getTime()
使用 UTC 表示时间。
来自 MDN:
The Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
我的印象是 Date.now()
是自我们 local 时区的纪元以来的毫秒数。如果是这样的话,我怎样才能得到自 UTC 时间纪元以来的毫秒数?我猜这将是很长的路要走:
new Date(new Date().toUTCString()).getTime()
有没有更快的方法?
Date.now()
and new Date().getTime()
使用 UTC 表示时间。
来自 MDN:
The Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.