node.js timezone independent Date.now()

编程入门 行业动态 更新时间:2024-10-27 19:30:38
本文介绍了node.js timezone independent Date.now()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在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()

本文发布于:2023-10-24 02:53:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522729.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:js   node   timezone   Date   independent

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!