getTimezoneOffset() method returns the difference, in minutes, between a date as evaluated in the UTC time zone, and the same date as evaluated in the local time zone.
The difference, in minutes, between the date as evaluated in the UTC time zone and as evaluated in the local time zone. The actual local time algorithm is implementation-defined, and the return value is allowed to be zero in runtimes without appropriate data.
date.getTimezoneOffset() returns the difference, in minutes, between
The number of minutes returned by
getTimezoneOffset() is positive if the local time zone is behind UTC, and negative if the local time zone is ahead of UTC. For example, for UTC+10,
-600 will be returned.
|Current time zone||Return value|
In a region that annually shifts in and out of Daylight Saving Time (DST), as
date varies, the number of minutes returned by calling
getTimezoneOffset() can be non-uniform.
getTimezoneOffset()'s behavior will never differ based on the time when the code is run — its behavior is always consistent when running in the same region. Only the value of
date affects the result.
In most implementations, the IANA time zone database (tzdata) is used to precisely determine the offset of the local timezone at the moment of the
date. However, if such information is unavailable, an implementation may return zero.
// Create a Date instance for the current time const currentLocalDate = new Date(); // Create a Date instance for 03:24 GMT-0200 on May 1st in 2016 const laborDay2016at0324GMTminus2 = new Date("2016-05-01T03:24:00-02:00"); currentLocalDate.getTimezoneOffset() === laborDay2016at0324GMTminus2.getTimezoneOffset(); // true, always, in any timezone that doesn't annually shift in and out of DST // false, sometimes, in any timezone that annually shifts in and out of DST
In regions that use DST, the return value may change based on the time of the year
date is in. Below is the output in a runtime in New York, where the timezone is UTC-05:00.
const nyOffsetSummer = new Date("2022-02-01").getTimezoneOffset(); // 300 const nyOffsetWinter = new Date("2022-08-01").getTimezoneOffset(); // 240
Due to historical reasons, the timezone a region is in can be constantly changing, even disregarding DST. For example, below is the output in a runtime in Shanghai, where the timezone is UTC+08:00.
const shModernOffset = new Date("2022-01-27").getTimezoneOffset(); // -480 const shHistoricalOffset = new Date("1943-01-27").getTimezoneOffset(); // -540
This is because during the Sino-Japanese War when Shanghai was under Japanese control, the timezone was changed to UTC+09:00 to align with Japan's (in effect, it was a "year-round DST"), and this was recorded in the IANA database.
|ECMAScript Language Specification |
BCD tables only load in the browser