Source @ github

Date

Date – Creates a Date object.

Description

new Date([mixed date, [integer month, [integer day, [integer hour, [integer minutes, [integer seconds, [integer milliseconds]]]]]]])

The range of dates that can be represented in a Date object is approximately 100000000 days (270000 years) on either side of 1 January 1970.

Parameters

Name Description Type Default Optional
date See date below. mixed Yes
month Integer between 0 and 11. integer Yes
day Integer between 1 and 31. integer Yes
hour Integer between 0 and 23. integer Yes
minutes Integer between 0 and 59. integer Yes
seconds Integer between 0 and 59. integer Yes
milliseconds Integer between 0 and 999. integer Yes
Date parameter

Can be a date string, timestamp or year if multiple paramters is provided.

Not provided

Current time.

Year

If called with multiple parameters, the first one will be assumed to be the year.

This input is local time.

Integer

If date is provided as an integer, it sill be number of milliseconds since 1 January 1970 00:00:00 UTC.

String

String value representing a date.

This input is local time if no timezone is specified.

Examples

Example #1 – Date example
console.log(new Date()); // Current time. console.log(new Date(undefined)); // Invalid Date.
console.log(new Date(2015, 9, 21)); // 21 October 2015 console.log(new Date(2015, 9, 21, 16, 29, 00)); // 21 October 2015 16:29:00
console.log(new Date(2015)); // 1 January 1970 01:00:02 (CET) // 31 December 1969 19:00:02 (EST) console.log(new Date(1445437740000)); // 21 October 2015 16:29:00 (CEST) // 21 October 2015 10:29:00 (EDT)
console.log(new Date("Oct 21, 2015 16:29:00")); // 21 October 2015 16:29:00 console.log(new Date("21 October 2015 16:29:00")); // 21 October 2015 16:29:00 console.log(new Date("2015-10-21T16:29:00.000Z")); // 21 October 2015 18:29:00 (CEST) // 21 October 2015 12:29:00 (EDT) console.log(new Date("2015-10-21T16:29:00")); // Unpredictable parsing. console.log(new Date("2015-10-21 16:29:00")); // Only supported by some interpreters. console.log(new Date("Invalid time string")); // Invalid Date.

External references