diff --git a/files/en-us/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html b/files/en-us/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html index d4cd8c5700906c7..a1aefe68ccae273 100644 --- a/files/en-us/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html +++ b/files/en-us/web/javascript/reference/global_objects/date/gettimezoneoffset/index.html @@ -10,68 +10,70 @@ ---
{{JSRef}}
-

The getTimezoneOffset() method returns the time zone - difference, in minutes, from current locale (host system settings) to UTC.

+

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.

{{EmbedInteractiveExample("pages/js/date-gettimezoneoffset.html")}}

Syntax

-
dateObj.getTimezoneOffset()
+
date.getTimezoneOffset()

Return value

-

A number representing the time-zone offset, in minutes, from the date based on current - host system settings to UTC.

+

The difference, in minutes, between date, as evaluated in the UTC time zone, and as evaluated in the local time zone.

Description

-

The time-zone offset is the difference, in minutes, from local time to UTC.

+

date.getTimezoneOffset() returns the difference, in minutes, between date as evaluated in the UTC time zone, and date 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.

-

Note that this means that the offset is positive if the local timezone is behind UTC, - and negative if it is ahead. For example, for time zone UTC+10:00 (Australian Eastern - Standard Time, Vladivostok Time, Chamorro Standard Time), -600 will be - returned.

+

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 LocaleUTC-8UTCUTC+3
Return Value4800-180
Current time zoneUTC-8UTCUTC+3
Return Value4800-180
-

The time zone offset returned is the one that applies for the Date that it's called on. -

+

Varied results in Daylight Saving Time (DST) time zones

-

If the host system is configured for daylight saving, the offset will change depending - on the date and time that the Date represents and that daylight saving applies.

+

In a time zone that annually shifts in and out of Daylight Saving Time (DST), the number of minutes returned by calling getTimezoneOffset() can vary.

+

Consider a given local time zone and a date date1 that are both in DST, and consider minutes, the number of minutes returned by calling date1.getTimezoneOffset(); then: -

Examples

+ + +

In a time zone that doesn’t annually shift in and out of Daylight Saving Time (DST), the number of minutes returned by calling getTimezoneOffset() always returns the same number of minutes, regardless of the date instance it’s called from.

-

Using getTimezoneOffset()

+
+

Note: The above description is a simplification. In implementations, the {{InterWiki("wikipedia", "Daylight_saving_time#IANA_time_zone_database", "IANA time zone database")}} (tzdata) is used for precisely determining the effect of DST on the calculation of the time-zone difference.

+
-
// Get current timezone offset for host device
-let x = new Date();
-let currentTimeZoneOffsetInHours = x.getTimezoneOffset() / 60;
-// 1
+

Examples

-// Get timezone offset for International Labor Day (May 1) in 2016 -// Be careful, the Date() constructor uses 0-indexed months, so May is -// represented with 4 (and not 5) -let laborDay = new Date(2016, 4, 1) -let laborDayOffset = laborDay.getTimezoneOffset() / 60; +
// Create a Date instance for the current time
+let currentLocalDate = new Date();
+// Create a Date instance for 03:24 GMT-0200 on May 1st in 2016
+let laborDay2016at0324GMTminus2 = new Date('May 1, 2016 03:24:00 GMT-0200');
+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
 

Specifications