I know how to get the timezone offset, but what I need is the ability to detect something like "America/New York." Is that even possible from JavaScript or is that something I am going to have to guestimate based on the offset?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Most upvoted answer is probably the best way to get the timezone, however,
Intl.DateTimeFormat().resolvedOptions().timeZone
returns IANA timezone name by definition, which is in English.If you want the timezone's name in current user's language, you can parse it from
Date
's string representation like so:Tested in Chrome and Firefox.
Ofcourse, this will not work as intended in some of the environments. For example, node.js returns a GMT offset (e.g.
GMT+07:00
) instead of a name. But I think it's still readable as a fallback.P.S. Won't work in IE11, just as the
Intl...
solution.