Technically, a more correct spell:
Intl.DateTimeFormat().resolvedOptions().timeZone
Unfortunately, not all implementations currently support Intl API timezone functions. Therefore, until this returns the actual IANA timezone in Chrome, it will not do so in FireFox and several other browsers.
The kangax Intl compatibility table shows this function as a sub-item under the DateTimeFormat object labeled resolvedOptions().timeZone defaults to the host environment .
See the following FireFox work items:
- Error 1158733 - Detecting a system time zone from the Javascript Internationalization API
- Error 895737 - DateTimeFormat does not track the current time zone
- Error 837961 - Add IANA time zone name support to the internationalization API.
In the meantime, there are two viable alternatives:
- jsTimeZoneDetect - which focuses on the task of guessing the time zone.
- moment-time is an addition to the popular moment.js , and contains the
moment.tz.guess() API to try to guess the user's time zone.
Please note that both of them will internally try to use the Intl API, if it is accessible and working, before trying to use additional guessing algorithms.
Also note that it is best practice to never rely solely on detecting / guessing the time zone, but rather use it to select a reasonable default value from the time zone control. Always give the user the opportunity to select the desired time zone. This is important because they currently have a computer installed in the time zone, which may or may not be the time zone that they would like to use in your application. For example, it is common for a web calendar (e.g. Google Calendar or Outlook.com) so that the user can set the time zone in his user profile.
source share