Using an offset to calculate Timezone is a wrong approach, and you will always encounter problems. Time zones and daylight saving rules may change on several occasions during a year, and It’s difficult to keep up with changes.
To get the system’s IANA timezone in JavaScript, you should use
console.log(Intl.DateTimeFormat().resolvedOptions().timeZone)
Run code snippetExpand snippet
As of September 2019, this works in 95% of the browsers used globally.
Old compatibility information
ecma-402/1.0 says that timeZone may be undefined if not provided to constructor. However, future draft (3.0) fixed that issue by changing to system default timezone.
In this version of the ECMAScript Internationalization API, the
timeZoneproperty will remain undefined if notimeZoneproperty was provided in the options object provided to theIntl.DateTimeFormatconstructor. However, applications should not rely on this, as future versions may return a String value identifying the host environment’s current time zone instead.
in ecma-402/3.0 which is still in a draft it changed to
In this version of the ECMAScript 2015 Internationalization API, the
timeZoneproperty will be the name of the default time zone if notimeZoneproperty was provided in the options object provided to theIntl.DateTimeFormatconstructor. The previous version left thetimeZoneproperty undefined in this case.