Home > front end >  is JS command `new Date()` the same across different devices and timezones?
is JS command `new Date()` the same across different devices and timezones?

Time:12-25

Lets say I have a server running in America and Europe, and I run new Date().getTime() on both machines at the same time, would they both return sameish timestamp?

or could 1 be drastically different?

What affects that return, is it the time configured on the machine executing it?

CodePudding user response:

getTime returns the number of milliseconds since January 1st 1970, UTC, so it doesn’t depend on the local machine time offset.

CodePudding user response:

Date.getTime() returns the number of milliseconds since the Unix Epoch. Regardless of the time zone configuration of either device, assuming that both devices have synchronized clocks, the values should be essentially identical.

  • Related