JavaScript Editor JavaScript Validator     JavaScript Editor 



Team LiB
Previous Section Next Section

Chapter 9: Date, Time, and Timers

Overview

In Chapter 4 we saw that the concepts of date and time are embodied in JavaScript through the Date object. We looked at some of the properties and methods of the Date object, including the following:

One thing that we didn't cover in that chapter was the idea that the time depends on your location around the world. In this chapter we'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 website and want to organize a chat for a certain date and time. Simply stating 15:30 is not good enough if your website attracts international visitors. The time 15:30 could be Eastern Standard Time, Pacific 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 U.S. Wouldn't it be great if you could automatically convert the time to the user's time zone? In this chapter we'll see how.

As well as looking at world time, we'll also be looking at how to create a timer in a web page. We'll see that by using the timer, we can trigger code, either at regular intervals or just once (for example, five seconds after the page has loaded). We'll see how we 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 our web applications. Finally, we'll be using the timer to enable the users of our trivia quiz to give themselves a time limit for answering the questions.


Team LiB
Previous Section Next Section


JavaScript Editor JavaScript Validator     JavaScript Editor


©