From 21ea080d6927bafa49292e7d927d160278cb6a10 Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Thu, 7 Jan 2021 23:02:03 +0900 Subject: [PATCH] More precisely describe getTimezoneOffset() --- .../date/gettimezoneoffset/index.html | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) 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 14e5f43e3387f4c..ed7c2e3d528eced 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,28 +10,30 @@ ---
{{JSRef}}
-

The getTimezoneOffset() method returns the time-zone difference, in minutes, between UTC time and local time.

+

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, between UTC and local time.

+

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, between UTC time and local time.

+

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.

-

Note that this means that the offset is positive if the local time zone is behind UTC, and negative if the local time zone is ahead of UTC. 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. - + @@ -47,14 +49,24 @@

Description

Current LocaleCurrent time zone UTC-8 UTC UTC+3
+

Varied results in Daylight Saving Time (DST) time zones

+ +

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: + +

+ +

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.

+
-

{{jsxref("Date")}} instances do not store a time zone — instead they just store a single value representing the number of milliseconds that have elapsed since midnight on January 1, 1970, UTC — so regardless of what {{jsxref("Date")}} instance the getTimezoneOffset() method is called from, the result isn’t calculated based on the value of the particular {{jsxref("Date")}} instance, but is instead always just the difference between UTC time and local time.

+

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.

Examples

-

Using getTimezoneOffset()

-
// 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