使用EPOC值JavaScript计算客户端服务器UTC偏移量

发布于 2025-01-31 01:00:39 字数 284 浏览 3 评论 0原文

我们正在尝试通过使用从后端API发送的EPOC值来计算客户端服务器时间的偏移,而在此操作中,我遇到了本地浏览器/客户端端的问题。

当我从后端API IE ESERVEREPVALUE获得EPOC时?

const serverdate = new Date(1653107370620)

serverdate = SAT 5月21日2022 09:59:30 GMT+0530(语言环境浏览器日期和时间)

如何使用EPOC获得服务器UTC时间来计算客户端的偏移?

We are trying to calculate the client-server time offset by using EPOC value sent from backend API, when doing that I am running into an issue in local browser/client side.

when i get EPOC from backend API I.e. serverEpocValue = 1653107370620 and trying to compare it with the local epoc value the difference is not 6 hours as I expected, it's around few milliseconds difference, why is epoc value close to local time instead of the server time?

const serverdate = new Date(1653107370620)

serverDate =
Sat May 21 2022 09:59:30 GMT+0530 (locale browser date and time)

How do we get the server UTC time using epoc to calculate the offset in the client side?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

絕版丫頭 2025-02-07 01:00:39

设施的时间date.now()将始终从1970年1月1日UTC开始,并且不考虑时区。如果需要获得时区偏移,则应使用date.getTimeZoneOffset

https://developer.mozilla.org/en-us/docs/docs/web/javascript/javascript/global_object/global_objects/date/getTime/getTimeZoneOfkseft

global_objects/date/getTimeZoneOffset“ rel =“ nofollow noreferrer 分钟。

The time through facilities Date.now() will always be in milliseconds from Jan 1 1970 UTC and does not consider timezones. If you need to get the timezone offset you should use something like Date.getTimezoneOffset

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

which will return the offset in minutes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文