Date.prototype.getTimezoneOffset()
The 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.
Syntax
getTimezoneOffset()
Return value
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.
Description
date.getTimezoneOffset()
returns the difference, in minutes, between date
as evaluated in the UTC time zone and as evaluated in the local time zone — that is, the time zone of the host system in which the browser is being used (if the code is run from the Web in a browser), or otherwise the host system of whatever JavaScript runtime (for example, a Node.js environment) the code is executed in.
Negative values and positive values
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 |
---|---|
UTC-8 | 480 |
UTC | 0 |
UTC+3 | -180 |
Varied results in Daylight Saving Time (DST) regions
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.
Note:
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 ofdate
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.