Search code examples
javascripttimezonetimestampepochgettime

Why getTime() in Javascript is timezone independent?


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)?


Solution

  • You're referring to UTC. It is always based on GMT time, so no matter where you execute the code from, GMT time is consistent.