O'Reilly logo

Web Technology: Theory and Practice by M. Srinivasan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.8 DATE OBJECT

A Date is an object in JavaScript. An instance is created using the Date() object.

   var myDt = new Date();                  //returns current date
                                           //defined in the local machine
   var myDt = new Date(1926, 10, 23);      //pass date in the order—
                                           //year, month (0-11), day

Note that the month follows 0–11 rather than 1–12 convention. The time is optional. If it is required, pass additional parameters for hour, minutes, seconds and milliseconds.

 

Date display

 

Fig. 4.14 Date display

 

The Date object has several get and set methods for getting and setting date components. The following is a list.

  • d.getFullYear
  • d.getMonth—returns an index between 0 and 11
  • d.getHour ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required