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?
The Internationalization API supports getting the user timezone, and is supported in all current browsers.
Keep in mind that on some older browser versions that support the Internationalization API, the
timeZone
property is set toundefined
rather than the user’s timezone string. As best as I can tell, at the time of writing (July 2017) all current browsers except for IE11 will return the user timezone as a string.You can simply write your own code by using the mapping table here: http://www.timeanddate.com/time/zones/
or, use moment-timezone library: http://momentjs.com/timezone/docs/
See
zone.name; // America/Los_Angeles
or, this library: https://github.com/Canop/tzdetect.js
In javascript , the Date.getTimezoneOffset() method returns the time-zone offset from UTC, in minutes, for the current locale.
Moment'timezone will be a useful tool. http://momentjs.com/timezone/
Convert Dates Between Timezones
Retrieve timezone by name (i.e. "America/New York")
You can use this script. http://pellepim.bitbucket.org/jstz/
Fork or clone repository here. https://bitbucket.org/pellepim/jstimezonedetect
Once you include the script, you can get the list of timezones in -
jstz.olson.timezones
variable.And following code is used to determine client browser's timezone.
Enjoy jstz!
Try this code refer from here