Java Reference
In-Depth Information
A useful tool in international time conversion is the getTimezoneOffset() method, which
returns the difference, in minutes, between the user's local time and UTC. One pitfall of
this is that you are assuming the user has correctly set his time zone on his computer. If not,
getTimezoneOffset() is rendered useless, as will be any local date and time methods if the
user's clock is incorrectly set.
Using the setTimeout() method, you found you could start a timer that would fire just
once after a certain number of milliseconds. setTimeout() takes two parameters: The first
is the function you want executed, and the second is the delay before that code is executed. It
returns a value, the unique timer ID that you can use if you later want to reference the timer;
for example, to stop it before it fires, you use the clearTimeout() method.
To create a timer that fires at regular intervals, you used the setInterval() method, which
works in the same way as setTimeout() , except that it keeps firing unless the user leaves the
page or you call the clearInterval() method.
In the next chapter, you turn your attention to the web browser itself and, particularly, the various
objects that it makes available for your JavaScript programming. You see that the use of browser
objects is key to creating powerful web pages.
exerCises
You can find suggested solutions to these questions in Appendix A.
1. Create a page that gets the user's date of birth. Then, using that information, tell her on what
day of the week she was born.
2. Create a web page similar to Example 5 in the “A Counting Clock” Try It Out, but make it
display only the hour, minutes, and seconds.
 
Search WWH ::




Custom Search