INTERNATIONAL TIME
If your Web site has an international audience, you may want to use UTC for dates.
Important methods for international time include:
toLocaleString();
//returns date and time as a string based on local time
toUTCString();
//returns date and time as a string based on UTC time, as shown in the previous section
getTimezoneoffset();
//gives difference in minutes between local time and UTC time
For example, this code:
var now = new Date(); document.write (now.toLocaleString() + "<br>"); document.write(now.toUTCString() + "<br>"); document.write(now.getTimezoneOffset() + "<br>");
returns this output to the page:
Sunday, September 14, 2003 3:22:17 AM Sun, 14 Sep 2003 09:22:17 UTC 360
You can use getTimezoneOffset() to determine the hours ahead or
behind of UTC, for example:
var myTime = new Date ();
var zone = myTime.getTimezoneOffset();
zone = zone / 60;
if (zone < 0) {
var factor = "later";
}
else
factor = "earlier";
document.write (myTime + " is " + zone +
" hours " + factor + " than UTC Time.");
returns this output to the page:
Sun Sep 14 03:42:47 MDT 2003 is 6 hours earlier than UTC Time.
JavaScript includes methods for UTC time that are equivalent to the methods mentioned earlier in this lesson, such as:
setUTCDate(); setUTCFullYear(); getUTCDate(); getUTCFullYear();
and so on.
