Node.js timezone independent Date.now ()

What is the general way timestamps synchronize between servers and clients in node.js, independent of timezone?

for example, the equivalent of Date.now (), which will provide the same time on the server and client. Preferably without any node.js modules or client-side libraries.

+5
source share
1 answer

JavaScript timestamps are always in UTC :

Time is measured in ECMAScript in milliseconds since January 01, 1970 UTC.

Date strings from different time zones can have the same time stamp.

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 ​​on different systems.

+13
source

Source: https://habr.com/ru/post/957072/


All Articles