Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  144] [ 5]  / answers: 1 / hits: 19214  / 11 Years ago, mon, august 26, 2013, 12:00:00

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.


More From » node.js

 Answers
228

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.


[#76117] Sunday, August 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravenl

Total Points: 338
Total Questions: 107
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
ravenl questions
Thu, Feb 18, 21, 00:00, 3 Years ago
Tue, Jan 12, 21, 00:00, 3 Years ago
Tue, Mar 17, 20, 00:00, 4 Years ago
;