在node.js中跨服务器和客户端同步timeStamps的常用方法是什么,不依赖于时区?
What is a common way to sync timeStamps across servers and clients in node.js, not dependent on timezone?
例如,Date.now()等效于将在服务器和客户端上提供相同的时间。 最好没有任何node.js模块或客户端库。
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.
推荐答案JavaScript时间戳始终基于 UTC :
JavaScript timestamps are always based in UTC:
时间以ECMAScript为单位,自UTC时间1970年1月1日起以毫秒为单位。
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并且, Date.now() 应该跨系统返回相对相似的值。
And, Date.now() should return relatively similar values across systems.
更多推荐
node.js timezone independent Date.now()
发布评论