Java Reference
In-Depth Information
getUTCFullYear()
getUTCHours()
getUTCMilliseconds()
getUTCMinutes()
getUTCMonth()
getUTCSeconds()
Notice that this time there is an additional method, getUTCDay(). This works in the same way as the
getDay() method and returns the day of the week as a number, from 0 for Sunday to 6 for Saturday.
Because the day of the week is decided by the day of the month, the month, and the year, there is no
setUTCDay() method.
Before moving on to look at timers, let's use your newly gained knowledge of the Date object and world
time to create a world time converter. Later in this chapter, when you've learned how to use timers,
you'll update the example to produce a world time clock.
Try It Out World Time Converter (Part I)
The World Time Converter lets you calculate the time in different countries:
<!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 3</title>
<script type=”text/javascript”>
var timeDiff;
var selectedCity;
var daylightSavingAdjust = 0;
function updateTimeZone()
{
var lstCity = document.form1.lstCity;
timeDiff = lstCity.options[lstCity.selectedIndex].value;
selectedCity = lstCity.options[lstCity.selectedIndex].text;
updateTime();
}
function getTimeString(dateObject)
{
var timeString;
var hours = dateObject.getHours();
if (hours < 10)
hours = “0” + hours;
var minutes = dateObject.getMinutes();
if (minutes < 10)
minutes = “0” + minutes;
var seconds = dateObject.getSeconds()
if (seconds < 10)
seconds = “0” + seconds;
timeString = hours + “:” + minutes + “:” + seconds;
return timeString;
Search WWH ::




Custom Search