Get client timezone (not GMT offset amount) in JS(在 JS 中获取客户端时区(不是 GMT 偏移量))
问题描述
我需要在 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 偏移量)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 JS 中获取客户端时区(不是 GMT 偏移量)


基础教程推荐
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01