7Date, Time, and Timers
WHAT YOU WILL LEARN IN THIS CHAPTER:
- Retrieving specific date and time information from a Date object
- Modifying the date and time of a Date object
- Delaying the execution of a function
- Executing a function at a set interval of time
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(), andgetFullYear()enable you to retrieve date values from inside aDateobject. - The
setDate(),setMonth(), andsetFullYear()methods enable you to set the date values of an existingDateobject. - The
getHours(),getMinutes(),getSeconds(), andgetMilliseconds()methods retrieve the time values in aDateobject. - The
setHours(),setMinutes(),setSeconds(), andsetMilliseconds()methods enable you to set the time values of an existingDateobject.
One thing not covered in that chapter is the idea that the time depends on your location around the world. In this chapter you correct 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access