O'Reilly logo

Object-Oriented JavaScript - Second Edition by Stoyan Stefanov, Kumar Chetan Sharma

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

Date

The Date constructor can be used with several types of input:

You can pass values for year, month, date of the month, hour, minute, second, and millisecond, like so:

> new Date(2015, 0, 1, 13, 30, 35, 505);
Thu Jan 01 2015 13:30:35 GMT-0800 (PST)
  • You can skip any of the input parameters, in which case they are assumed to be 0. Note that month values are from 0 (January) to 11 (December), hours are from 0 to 23, minutes and seconds 0 to 59, and milliseconds 0 to 999.
  • You can pass a timestamp:
    > new Date(1420147835505);
    Thu Jan 01 2015 13:30:35 GMT-0800 (PST)
    
  • If you don't pass anything, the current date/time is assumed:
    > new Date();
    Fri Jan 11 2013 12:20:45 GMT-0800 (PST)
    
  • If you pass a string, it's parsed in an attempt to extract a possible date ...

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