問題描述
我正在尋找一種檢測瀏覽器時區 ID 的方法(如 Olson 表中所定義)但我不關心確切的 ID,我只需要與用戶的 ID 相同的時區 ID(例如,如果用戶在巴黎,Europe/Rome"就可以了).
What I'm looking for is a way to detect the browser's timezone ID (as defined in the Olson tables) but I don't care for the exact ID, I just need the ID of a timezone that works the same as the user's one (for example "Europe/Rome" is fine if the user is in Paris).
我對當前的偏移量不感興趣,我真的需要時區,以便我可以將其發送到服務器以計算其他日期(服務器也有 Olson 表).
I'm not interested in the current offset, I really need the timezone so that I can send it to the server to do computations for other dates (the server has the Olson tables too).
理論上,因為我已經使用了 Moment.js 時區庫 并且已經包含了 Olson 表,所以我不需要其他任何東西,但我沒有找到任何 API 來進行檢測.我不知道它是否隱藏在某個地方,或者是否有人已經寫了它.問題之一是當前時區插件似乎將其數據保密.
Theoretically, as I already use Moment.js timezone library and have included the Olson tables, I don't need anything else, but I don't find any API to do the detection. I don't know if it's hidden somewhere or if somebody has it already written. One of the problems is that the current timezone plugin seems to keep its data private.
我不'想要一個基于 Olson 表的另一個副本或提取的集成的解決方案(我必須維護),我知道有一些庫復制它們,我想使用我在 Moment.js 中已有的那些.
I dont' want a solution based on the integration of yet another copy or extract of the Olson tables (which I would have to maintain), I know there are a few libraries duplicating them, I want to use the ones I already have in Moment.js.
推薦答案
moment 現在有 guess()
API 作為 描述在這里
moment now has the guess()
API as described here
這篇關于使用 moment.js 檢測當前用戶時區的 ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!