Date constructor

Explains the different forms of the date constructor.

The date constructor has four distinct forms.

Table 1. Date constructor
Syntax Effect
new Date() Returns the date representing the current time.
new Date(milliseconds)

Returns the date representing 00:00:00 UTC, January 1, 1970, plus milliseconds milliseconds. The argument can be negative, to express a date before 1970. If the argument cannot be converted to a number, the third constructor syntax is used.

Examples:

new Date(0) -> a date representing 00:00:00 UTC, January 1, 1970.

new Date(1000*60*60*24*20) -> a date representing twenty days after 00:00:00 UTC, January 1, 1970.

new Date(-1000*60*60*24*20) -> a date representing twenty days before 00:00:00 UTC, January 1, 1970.

new Date(string)

Returns the date described by string, which must have the form:

month/day/year hour:minute:second msecond

The date expressed in string is taken in local time.

Example:

new Date("12/25/1932 14:35:12 820")

A date representing December 25th, 1932, at 2:35 PM plus 12 seconds and 820 milliseconds, local time.

new Date(year,

month,

[ , day

[ , hours

[ , minutes

[ , seconds

[ , mseconds ]]]]])

Returns a new date representing the given year, month, day, and so on, taken in local time. The arguments are:

year: any integer.

month: range 0-11 (where 0=January, 1=February, and so on)

day: range 1-31, default 1

hours: range 0-23, default 0

minutes: range 0-59, default 0

seconds: range 0-59, default 0

mseconds: range 0-999, defaults to 0

Examples:

new Date(1932, 11, 25, 14, 35, 12, 820)

A date representing December 25th, 1932, at 2:35 PM plus 12 seconds and 820 milliseconds, local time.

new Date(1932, 11, 25)

A date representing December 25th, 1932, at 00:00, local time.