Java Reference
In-Depth Information
World Time
The concept of now means the same point in time everywhere in the world. However, when that point
in time is represented by numbers, those numbers differ depending on where you are. What is needed
is a standard number to represent that moment in time. This is achieved through Coordinated Universal
Time (UTC), which is an international basis of civil and scientifi c time and was implemented in 1964.
It was previously known as GMT (Greenwich Mean Time), and, indeed, at 0:00 UTC it is midnight in
Greenwich, London.
The following table shows local times around the world at 0:00 UTC time.
San
ÅtFrancisco
New York
(EST)
Greenwich,
London
Berlin,
Germany
Tok yo,
Japan
4:00 pm
7:00 pm
0:00 (midnight)
1:00 am
9:00 am
Note that the times given are winter times — no daylight savings hours are taken into account.
The support for UTC in JavaScript comes from a number of methods of the Date object that are similar
to those you have already seen. For each of the set-date- and get-date-type methods you've seen so
far, there is a UTC equivalent. For example, whereas setHours() sets the local hour in a Date object,
setUTCHours() does the same thing for UTC time. You'll be looking at these methods in more detail in
the next section.
In addition, three more methods of the Date object involve world time.
You have the methods toUTCString() and toLocaleString(), which return the date and time
stored in the Date object as a string based on either UTC or local time. Most modern browsers also
have these additional methods: toLocaleTimeString(), toTimeString(), toLocaleDateString(),
and toDateString().
If you simply want to fi nd out the difference in minutes between the current locale's time and UTC,
you can use the getTimezoneOffset() method. If the time zone is behind UTC, such as in the United
States, it will return a positive number. If the time zone is ahead, such as in Australia or Japan, it will
return a negative number.
Try It Out The World Time Method of the Date Object
In the following code you use the toLocaleString(), toUTCString(), getTimezoneOffset(),
toLocaleTimeString(), toTimeString(), toLocaleDateString(), and toDateString() methods
and write their values out to the page.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>example 1</title>
</head>
Search WWH ::




Custom Search