How can I gather the visitor's time zone information? I need the Timezone, as well as the GMT offset hours.
相关问题
- 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?
With moment.js:
With momentjs, you can find current timezone as
It returns utc offset in minutes.
More Info
Example : Thu Jun 21 2018 18:12:50 GMT+0530 (India Standard Time)
O/P : +0530
This is very good work for me:
Note that not all timezones are offset by whole hours: for example, Newfoundland is UTC minus 3h 30m (leaving Daylight Saving Time out of the equation).
You can use:
moment-timezone
Browser time zone detection is rather tricky to get right, as there is little information provided by the browser.
Moment Timezone uses
Date.getTimezoneOffset()
andDate.toString()
on a handful of moments around the current year to gather as much information about the browser environment as possible. It then compares that information with all the time zone data loaded and returns the closest match. In case of ties, the time zone with the city with largest population is returned.