Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Date

A date and time: creating, reading parts, calculating.

Available since: ES1

Syntax

new Date(value) / new Date(year, monthIndex, day, hours, minutes)

Parameters

ParameterTypeDescription
valuenumber | stringOptional. A timestamp in milliseconds or a date string. Without arguments — the current moment.
year, monthIndex, …numberOptional. 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 15

A date from an ISO string:

const date = new Date('2026-03-15T10:30:00Z');
 
console.log(date.toISOString());

Output:

2026-03-15T10:30:00.000Z

The current moment:

const now = new Date();
 
console.log(now.getFullYear());

Output:

2026

Notes

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

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.

Thanks for reading!

Donate to the site — we work hard for you.