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.
The now() method returns the milliseconds elapsed since 1 January 1970 00:00:00 UTC up until now as a Number. My understanding is that this timestamp is independent of any timezone offset, in other words it points to time at Zero timezone offset.
The static Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
Return value Calling the Date() function (without the new keyword) returns a string representation of the current date and time, exactly as new Date().toString() does.
JavaScript 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With