使用moment.js检测当前用户时区的ID [英] Detect the ID of the current user timezone using moment.js
问题描述
我正在寻找的是一种检测浏览器时区ID的方法(如 Olson表中所定义)但我不关心确切的身份证,我只需要一个与用户相同的时区ID(例如欧洲/罗马,如果用户在巴黎则很好)。
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.
推荐答案
现在有一个 guess()
API为此处描述
moment now has the guess()
API as described here
这篇关于使用moment.js检测当前用户时区的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!