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)
As of April 2022, this works in 93.5% 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
timeZone
property will remain undefined if notimeZone
property was
provided in the options object provided to theIntl.DateTimeFormat
constructor. 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
timeZone
property will be the name of the default time zone if no
timeZone
property was provided in the options object provided to the
Intl.DateTimeFormat
constructor. The previous version left the
timeZone
property undefined in this case.