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 s
Code:
var today = new Date();
console.log(today);
var t = today.getTime();
console.log(t);
My Computer in the UK:
Sat Sep 21 2013 03:45:20 GMT+0100 (GMT Daylight Time)
1379731520112
My VPS:
Sat, 21 Sep 2013 02:44:31 GMT
1379731471743
Difference between getTime values is 48,369 milliseconds (48s) out of sync not the 1 hour zone difference
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.
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:
var UTC=new Date(Date.UTC(serverYear,serverMonth-1,serverDate,0,0,0,0));
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):
"Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC."