我需要在 JS 中确定客户端时区(例如 CET、GMT、EST).获取偏移量很简单,但没有确定 TZ 所需的所有信息,至少不容易.我有一种感觉可能可以使用偏移量的组合,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.
所以,我目前陷入困境.
So, with that I am currently stuck.
参见 这个问题.在一般情况下这是不可行的,但要从可能情况的候选名单中选择默认时区,您可以做出一个不错的猜测.
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 偏移量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!