Date
A date and time: creating, reading parts, calculating.
Available since: ES1
Syntax
new Date(value) / new Date(year, monthIndex, day, hours, minutes)Parameters
| Parameter | Type | Description |
|---|---|---|
| value | number | string | Optional. A timestamp in milliseconds or a date string. Without arguments — the current moment. |
| year, monthIndex, … | number | Optional. Parts of the date; months count from zero: 0 is January, 11 is December. |
Return value
DateAn object holding a date and time.
Examples
A date from parts — the month counts from zero:
const date = new Date(2026, 2, 15);
console.log(date.getFullYear(), date.getMonth() + 1, date.getDate());Output:
2026 3 15A date from an ISO string:
const date = new Date('2026-03-15T10:30:00Z');
console.log(date.toISOString());Output:
2026-03-15T10:30:00.000ZThe current moment:
const now = new Date();
console.log(now.getFullYear());Output:
2026Notes
Months in Date are numbered from zero but days from one: new Date(2026, 0, 1) is January 1. This is the most common mistake with dates.
A Date object stores one moment in time and shows it in the computer's time zone. The string '2026-03-15' without a time is read as midnight UTC, while '2026-03-15T00:00' is midnight local time.
See also
- Date.now — Returns the current time as a number of milliseconds.
- Date.prototype.toISOString — Returns the date in ISO 8601 format in UTC.
- Intl.DateTimeFormat — Formats dates and times by language rules.
- Date.prototype.getFullYear — Returns the year.
In the tutorial
- Dates and time — The Date object in JavaScript: creating a date, reading the year, month and day, changing a date, the difference between dates and the ISO format.