問題描述
我需要在 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模板網!