最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - node.js timezone independent Date.now() - Stack Overflow

programmeradmin1浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 18

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.

发布评论

评论列表(0)

  1. 暂无评论