Share via


getTimezoneOffset Method

Returns the difference in minutes between the time on the host computer and Coordinated Universal Time (UTC).

function getTimezoneOffset() : Number

Remarks

The getTimezoneOffset method returns an integer value representing the number of minutes between the time on the current machine and UTC. These values are appropriate to the computer the script is executed on. If it is called from a server script, the return value is appropriate to the server. If it is called from a client script, the return value is appropriate to the client.

This number will be positive if you are behind UTC (for example, Pacific Daylight Time), and negative if you are ahead of UTC (for example, Japan).

For example, suppose a client in Los Angeles contacts a server in New York City on December 1. getTimezoneOffset returns 480 if executed on the client, or 300 if executed on the server.

Example

The following example illustrates the use of the getTimezoneOffset method.

function TZDemo(){
   var d, tz;
   s = "The current local time is ";
   d = new Date();
   tz = d.getTimezoneOffset();
   if (tz < 0)
      s += tz / 60 + " hours after UTC";
   else if (tz == 0)
      s += "UTC";
   else
      s += tz / 60 + " hours before UTC";
   return(s);
}

Requirements

Version 1

Applies To:

Date Object

See Also

Other Resources

Methods

Change History

Date

History

Reason

March 2009

Modified sample code.

Content bug fix.