Returns the difference in minutes between the time on the host computer and Coordinated Universal Time (UTC).
function getTimezoneOffset() : Number
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.
The following example illustrates the use of the getTimezoneOffset method.
function TZDemo()
{
var d = new Date();
var minutes = d.getTimezoneOffset();
var s = "";
s += "The current local time is ";
s += minutes / 60;
if (minutes < 0)
s += " hours after UTC";
else
s += " hours before UTC";
return(s);
}
Applies To:
Other Resources
In the remarks, it's already written that "This number (variable minute in the example) will be positive if you are behind UTC". Saying "behind" is equivalent to saying "after". So, when minute is positive (in the else-clause), the string should have been " hours after UTC" instead of "before". The if-condition should have been (minutes > 0), not (minutes < 0).
But even if this is corrected, for people ahead of UTC, eg, in China, you'll have
The current local time is -8 hours before UTC.
A corrected and better one, without considering the situation where minute=0, should have been
function TZDemo() {
var d = new Date();
var minutes = d.getTimezoneOffset();
var s = "The current local time is ";
if (minutes > 0)
s += (minutes / 60) + " hour(s) after UTC";
else
s += (-minutes / 60) + " hour(s) before UTC";
return(s);
}