在JS中获取客户端时区(不是GMT偏移量) [英] Get client timezone (not GMT offset amount) in JS

查看:943
本文介绍了在JS中获取客户端时区(不是GMT偏移量)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要确定JS中的客户端时区(例如CET,GMT,EST)。获得偏移是直截了当的,但没有确定TZ所需的所有信息,至少不容易。我有一种感觉,可能可以使用offset的组合,DST是否正在使用和有效等等,但我希望有人已经完成了这项工作,特别是考虑到奇怪的处理时间的例外。

I need to determine the client timezone (e.g. CET, GMT, EST) in JS. Getting the offset is straightforward, but doesn't have all the info necessary to determine the TZ, at least not easily. I have a feeling it might be possible to use a combination of offset, whether DST is in use and in effect, etc. but I'm hoping someone else has done the work already, especially considering the weird exceptions when dealing with time.

这个问题是相似的,但问题和答案都是基于(不正确的)假设,每个浏览器的DateString格式包括时区的名称 - 它不是。这是一个实现细节。

This question is similar but both the question and the answer are based on the (incorrect) assumption every browser's DateString format includes the name of the timezone - which it does not. That is an implementation detail.

所以,我目前卡住了。

推荐答案

参见这个问题。在一般情况下不可行,但是从可能情况的候选名单中选择默认时区,您可以做出一个体面的猜测。

See this question. It's not doable in the general case, but for picking a default timezone from a shortlist of likely cases, you can make a decent guess.

允许用户覆盖它当你猜错了。

Allow the user to override it for when you guess wrong.

这篇关于在JS中获取客户端时区(不是GMT偏移量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆