Date

This object represents dates; you can create it in several ways:

var the_date = new Date();
var the_date = new Date("month dd, yyyy");
var the_date = new Date("month dd, yyyy hh:mm:ss");
var the_date = new Date( yy, mm, dd);
var the_date = new Date(milliseconds);

Here month is the name of the month (January, February, and so on), dd is a two-digit day (01 to 31), yyyy is a four-digit year (0000 to 9999), and so on. If you create a Date object without anything in the parentheses, JavaScript will assume you mean the current date and time according to the computer that's running the JavaScript.

The Date object has numerous methods for getting and setting the date. Except where noted, the methods work for all JavaScript-enabled browsers.

Methods ...

Get The Book of JavaScript, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.