What is a common way to sync timeStamps across servers and clients in node.js, not dependent on timezone?
e.g., a Date.now() equivalent that would provide the same time on the server and client. Preferably without any node.js modules, or client side libraries.
What is a common way to sync timeStamps across servers and clients in node.js, not dependent on timezone?
e.g., a Date.now() equivalent that would provide the same time on the server and client. Preferably without any node.js modules, or client side libraries.
Share Improve this question edited May 14, 2015 at 15:42 Juergen 12.7k7 gold badges41 silver badges56 bronze badges asked Aug 26, 2013 at 18:44 ArkahnXArkahnX 4151 gold badge5 silver badges10 bronze badges 2- 2 This thread may be of interest: The best way to synchronize client-side javascript clock with server date – dc5 Commented Aug 26, 2013 at 18:53
- @dc5 I ended up using something similar to that thread, but I greatly simplified it. – ArkahnX Commented Aug 27, 2013 at 19:52
1 Answer
Reset to default 18JavaScript timestamps are always based in UTC:
Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC.
Date strings from different timezones can have the same timestamp.
var a = "2013-08-26 12:00 GMT-0800";
var b = "2013-08-27 00:00 GMT+0400";
console.log(Date.parse(a) === Date.parse(b)); // true
console.log(Date.parse(a)); // 1377547200000
console.log(Date.parse(b)); // 1377547200000
And, Date.now()
should return relatively similar values across systems.