Java Reference
In-Depth Information
FiGure 7-3  
So how does this example work? You declare a variable, myDate , and set it to a new Date object.
Because you haven't initialized the Date object to any value, it contains the local current date and time.
Then, using the setUTC methods, you set the hours, minutes, and seconds so that the time is 12:00:00
UTC (midday, not midnight).
Now, when you write out the value of myDate as a UTC string, you get 12:00:00 and today's date.
When you write out the value of the Date object as a local string, you get today's date and a time that
is the UTC time 12:00:00 converted to the equivalent local time. The local values you'll see, of course,
depend on your time zone. For example, New Yorkers will see 08:00:00 during the summer and
07:00:00 during the winter because of daylight savings. In the United Kingdom, in the winter you'll see
12:00:00, but in the summer you'll see 13:00:00.
For getting UTC dates and times, you have the same functions you would use for setting UTC dates
and times, except that this time, for example, it's getUTCHours() , not setUTCHours() :
getUTCDate()
getUTCDay()
getUTCFullYear()
getUTCHours()
getUTCMilliseconds()
getUTCMinutes()
getUTCMonth()
getUTCSeconds()
toISOString()
Search WWH ::




Custom Search