JavaScript Date getTimezoneOffset() Method

Definition and Usage

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

For example, if your time zone is GMT+2, the return value is -120.

Note:Due to the convention of using daylight saving time, the return value of this method is not a constant.

Tip:Coordinated Universal Time (UTC) is the standard time set by the world time standard.

Note:UTC time is the same as GMT (Greenwich Mean Time).

Description

The getTimezoneOffset() method returns the number of minutes between local time and GMT or UTC time. In fact, this function tells us the time zone in which JavaScript code is running and whether the specified time is daylight saving time.

The reason why it is measured in minutes instead of hours is that some time zones occupied by countries are even less than an hour apart.

Example

Returns the time difference between UTC and local time:

var d = new Date();
var n = d.getTimezoneOffset();

Try It Yourself

Syntax

Date.getTimezoneOffset()

Parameters

No parameters.

Technical Details

Return Value: A number representing the time difference between UTC and local time, in minutes.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome IE Firefox Safari Opera
getTimezoneOffset() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Date

Tutorial:JavaScript Date Format

Tutorial:JavaScript Object Constructor