The Date object in JavaScript.

Basic Usage

var myDate = new Date(DateInfo)

Here are the various possibilities for DateInfo:

A JavaScript date is measured in milliseconds since midnight 01 January, 1970 UTC (1970-01-01 00:00:00). A day holds 86,400,000 ms. The Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC.

Try to use the FullYear variations instead of Year variations.

Methods

.getX()

These methods get/retrieve some portion of its date object. Unless otherwise noted, all are implemented JS 1.0; ECMA-262. The variations include:

The UTC variations temporarily converts the date object to UTC. Magically adjusts for daylight saving time. Unless otherwise noted, all are implemented JS 1.3; ECMA-262.

Note that there is no getUTCTime(), getUTCTimezoneOffset(), or getUTCYear().

.now()

Implemented: JS not; ECMA-262 not.
Static method
Returns milliseconds since midnight 01 January, 1970 UTC for the system date and time. [This isn't part of any standard but is part of many common libraries.]

var d = new Date();
d.now(); //Won't work
Date.now(); //OK

.parse(dateString)

Implemented: JS 1.0; ECMA-262.
Static method
Returns milliseconds since midnight 01 January, 1970 UTC for the given datetime string. Parse takes datetime strings like the following:

//Unless you are locally in GMT, these should return different values
alert(Date.parse("Mon, 25 Dec 1995 13:30:00"));
alert(Date.parse("Mon, 25 Dec 1995 13:30:00 GMT"));

.setX()

These methods set/specify some portion of its date object. Unless otherwise noted, all are implemented JS 1.0; ECMA-262.

Note that there is no setDay(), setTimezoneOffset(), setYear().

The UTC variations temporarily converts the date object to UTC then set the value of its date object. Magically adjusts for daylight saving time. Unless otherwise noted, all are implemented JS 1.3; ECMA-262.

Note that there is no setUTCTime().

.toY()

These methods usually translate a date object (or a portion of it) to a string of particular formats. Unless otherwise noted, all are implemented JS 1.0; ECMA-262. The variations include:

.UTC(year, month[, date[, hour[, min[, sec[, ms]]]]])

Implemented: JS 1.0; JS 1.3 added ms parameter; ECMA-262.
Static method
1000-9999, 0-11 where 0=Jan, 1-31, 0-23, 0-59, 0-59, 0-9999. Returns milliseconds since midnight 01 January, 1970 UTC.EG:

var d = new Date();
d.UTC(2008,3); //Won't work
Date.UTC(2008,3); //OK

Page Modified: (Hand noted: 2007-08-08 17:58:30Z) (Auto noted: 2008-09-24 18:10:01Z)