Java Reference
In-Depth Information
FiGure 7-1  
Within the rest of the script block, you obtain the results from various time and date functions. The
results are stored in variable html , and this is then displayed in the page.
In the following line, you store the string returned by the toUTCString() method in the html variable:
var html = "<p>UTC Time is " + localTime.toUTCString() + "</p>";
This converts the date and time stored inside the localTime Date object to the equivalent UTC date
and time.
Then the following line stores a string with the local date and time value:
html += "Local Time is " + localTime.toLocaleString() + "</p>";
Because this time is just based on the user's clock, the string returned by this method also adjusts for
daylight savings time (as long as the clock adjusts for it).
Next, this code stores a string with the difference, in minutes, between the local time zone's time and
that of UTC:
html += "<p>Time Zone Offset is " + localTime.getTimezoneOffset() + "</p>";
You may notice in Figure 7-1 that the difference between New York time and UTC time is written to be
240 minutes, or 4 hours. Yet in the previous table, you saw that New York time is 5 hours behind UTC.
So what is happening?
Well, in New York on March 30, daylight savings hours are in use. Whereas in the summer it's 8:00
p.m. in New York when it's 0:00 UTC, in the winter it's 7:00 p.m. in New York when it's 0:00 UTC.
Therefore, in the summer the getTimezoneOffset() method returns 240 , whereas in the winter the
getTimezoneOffset() method returns 300 .
Search WWH ::




Custom Search