get client time zone from browser

2019-01-02 17:11发布

Is there a reliable way to get a timezone from client browser? I saw the following links but I want a more robust solution.

Auto detect a time zone with JavaScript

Timezone detection in JavaScript

8条回答
闭嘴吧你
2楼-- · 2019-01-02 17:46

For now, the best bet is probably jstz as suggested in mbayloon's answer.

For completeness, it should be mentioned that there is a standard on it's way: Intl. You can see this in Chrome already:

> Intl.DateTimeFormat().resolved.timeZone
"America/Los_Angeles"

(This doesn't actually follow the standard, which is one more reason to stick with the library)

查看更多
看淡一切
3楼-- · 2019-01-02 17:51

No. There is no single reliable way and there will never be. Did you really think you could trust the client?

查看更多
登录 后发表回答