If JavaScript (new Date()).getTime()
is run from 2 different timezones simultaneously, will you get the same value?
Will this value be affected by the system time set on the machine where the browser is running?
If JavaScript (new Date()).getTime()
is run from 2 different timezones simultaneously, will you get the same value?
Will this value be affected by the system time set on the machine where the browser is running?
Yes, it's affected by system time. However, if the local time is correct (for whatever time zone the computer's set to), it should be the same in any time zone.
The ECMAScript standard says (§15.9.1.1):
Code:
My Computer in the UK:
My VPS:
Difference between getTime values is 48,369 milliseconds (48s) out of sync not the 1 hour zone difference
There will most likely always be a deviation between times attained between machines, but (I was wrong before) JavaScript Date() takes the UTC timezone as default.
Usually when time is essential, it's best to simply use the Server time and apply timezone corrections to that in the output if required.
You might want to do this if you want the same date as your server across different timezones:
You won't get the same value - difference between two client's browsers picking up their system time, but if their time is set up ok, you should get two times with a minimal difference since getting the timestamp using
new Date()
, you can get the UTC value (new Date()
returns number of milliseconds ellapsed since January 1, 1970, and that won't change), which is universal time and is location agnostic.