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 ...

Get Object-Oriented JavaScript - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.