从特定时区获取当前时间戳

从特定时区获取当前时间戳

本文介绍了从特定时区获取当前时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法可以从特定时区获取 javascript 中的 unix 时间戳?例如,我希望客户端向我发送一个 unix 时间戳,但我想让它与我的时区相匹配.

is there an easy way to get the unix timestamp in javascript from a specific timezone? for example i want the client send me an unix timestamp but i want to get it to match my timezone.

谢谢!

推荐答案

为什么不简单地以 UTC 格式发送日期,然后在服务器上转换为您的时区?

Why not simply send the date in UTC, and then convert to your timezone on the server?

var utcEpochSeconds = dateObj.getTime() + (dateObj.getTimezoneOffset() * 60000);

这篇关于从特定时区获取当前时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 09:07