JavaScript by Example: JavaScript Core Objects. Pt. 1 | 5
JavaScript by Example: JavaScript Core Objects. Pt. 1
The Date ObjectJavaScript provides the Date object for manipulating date and time.3 Like the String and Array objects, you can create as many instances as you like. As we'll see, the Date object provides a number of methods for getting or setting specific information about the date and time. The date is based on the UNIX date starting at January 1, 1970 (in Greenwich Mean Time4 [GMT]), and doesn't support dates before that time. Figure 9.12 gives you an idea of the difference between GMT and local time. Time is measured in milliseconds (one millisecond is one thousandth of a second). Since client-side JavaScript programs run on a browser, the Date object returns times and dates that are local to the browser, not the server. Of course, if the computer is not set to the correct time, then the Date object won't produce the expected results. Figure 9.13 shows a typical date and time control panel. 24-hour world time zones map with current time. Courtesy of http://www.worldtimezone.com/index24.html.The computer's date and time settings.If no arguments are passed to the Date object constructor, it returns the local date and time (based on the accuracy of the clock on your client machine). There are five formats that can be passed as arguments when creating a Date object. |
Using the Date Object Methods
The Date object comes with a large number of methods (see Table 9.3) and only a prototype property. For browser versions supporting Date methods, see http://www.w3schools.com/js/js_datetime.asp.




Find a programming school near you