Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Date ObjectJavaScript’s Date object provides methods for date and time manipulations. These can be performed based on the computer’s local time zone or based on World Time Standard’s Coordinated Universal Time (abbreviated UTC)—formerly called Greenwich Mean Time (GMT). Most methods of the Date object have a local time zone and a UTC version. Date-object methods are summarized in Fig. 11.10.
Fig. 11.10. Date-object methods.
The example in Figs. 11.11–11.12 demonstrates many of the local-time-zone methods in Fig. 11.10. The HTML document (Fig. 11.11) provides several sections in which the results are displayed.
Date-Object Constructor with No ArgumentsIn the script (Fig. 11.12), line 5 creates a new Date object. The new operator creates the Date object. The empty parentheses indicate a call to the Date object’s constructor with no arguments. A constructor is an initializer method for an object. Constructors are called automatically when an object is allocated with new. The Date constructor with no arguments initializes the Date object with the local computer’s current date and time.