我需要在 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模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)
XMLHttpRequest 的 getResponseHeader() 的限制?Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)