Java Reference
In-Depth Information
10
Date, Time, and Timers
Chapter 5 discussed that the concepts of date and time are embodied in JavaScript through the
Date object. You looked at some of the properties and methods of the Date object, including the
following:
The methods
getDate(), getDay(), getMonth(), and getFullYear() enable you to
retrieve date values from inside a Date object.
The
setDate() , setMonth() , and setFullYear() methods enable you to set the date
values of an existing Date object.
The
getHours(), getMinutes(), getSeconds(), and getMilliseconds() methods
retrieve the time values in a Date object.
The
setHours() , setMinutes() , setSeconds() , and setMilliseconds() methods
enable you to set the time values of an existing Date object.
One thing not covered in that chapter is the idea that the time depends on your location around
the world. In this chapter you'll be correcting that omission by looking at date and time in relation
to world time .
For example, imagine you have a chat room on your web site and want to organize a chat for a
certain date and time. Simply stating 15:30 is not good enough if your web site attracts interna-
tional visitors. The time 15:30 could be Eastern Standard Time, Pacifi c Standard Time, the time
in the United Kingdom, or even the time in Kuala Lumpur. You could of course say 15:30 EST
and let your visitors work out what that means, but even that isn't foolproof. There is an EST in
Australia as well as in the United States. Wouldn't it be great if you could automatically convert
the time to the user's time zone? In this chapter you'll see how.
In addition to looking at world time, you'll also be looking at how to create a timer in a web page.
You'll see that by using the timer you can trigger code, either at regular intervals or just once (for
example, fi ve seconds after the page has loaded). You'll see how you can use timers to add a real-
time clock to a web page and how to create scrolling text in the status bar. Timers can also be useful
for creating animations or special effects in your web applications. Finally, you'll be using the timer
to enable the users of your trivia quiz to give themselves a time limit for answering the questions.
Search WWH ::




Custom Search