3.9 The Date Object
var now = new Date( ); // Create an object holding the current date and time. // Create a Date object representing Christmas. // Note that months are zero-based, so December is month 11! var xmas = new Date(2000, 11, 25);
xmas.setFullYear(xmas.getFullYear( ) + 1); // Change the date to next Christmas. var weekday = xmas.getDay( ); // Christmas falls on a Tuesday in 2001. document.write("Today is: " + now.toLocaleString( )); // Current date/time.
The Date object also defines functions (not methods; they are not invoked through a Date object) to convert a date specified in string or numeric form to an internal millisecond representation that is useful for some kinds of date arithmetic.
You can find full documentation on the Date object and its methods in the core reference section of this book.