Date
The Date global object represents a single moment in time, stored as the number of milliseconds since midnight UTC on January 1, 1970, and provides methods that read and change that moment in UTC or in the host’s local time zone. That millisecond count is the date’s timestamp, and every other view of the date is computed from it:
> const launch = new Date("2026-03-15T14:30:00Z");
undefined
> launch.getTime()
1773585000000
> launch.toISOString()
'2026-03-15T14:30:00.000Z'
Date has been part of ECMAScript since its first edition and is Baseline Widely available. MDN now treats it as a legacy feature and points new code to Temporal, which reached Stage 4 in 2026 and is expected in ES2027.
Syntax
The Date constructor accepts nothing, a timestamp, a date string, or separate date and time components:
new Date()
new Date(<timestamp>)
new Date(<dateString>)
new Date(<year>, <monthIndex>[, <day>, <hours>, <minutes>, <seconds>, <ms>])
| Parameter | Description |
|---|---|
timestamp |
A number of milliseconds since the epoch. With no arguments at all, the date holds the current time |
dateString |
A string to parse. Only the ISO 8601 format, such as "2026-03-15T14:30:00Z", parses the same way in every engine |
year, monthIndex |
The year and the zero-based month, where 0 is January and 11 is December. Both are required in the component form |
day to ms |
Optional components, each allowed only when the ones before it are present. day defaults to 1, and the rest default to 0. The constructor reads every component as local time |
The new keyword creates a Date object. Calling Date() without it ignores any arguments and returns the current date and time as a string.
Key Static Methods and Properties
| Member | Kind | Description |
|---|---|---|
Date.now() |
Static method | Returns the current timestamp as a number |
Date.parse() |
Static method | Parses a date string and returns its timestamp, or NaN |
Date.UTC() |
Static method | Returns the timestamp for date and time components read as UTC |
Key Instance Methods and Properties
| Member | Kind | Description |
|---|---|---|
.getTime() |
Instance method | Returns the timestamp in milliseconds |
.getFullYear(), .getMonth(), .getDate(), .getDay() |
Instance method | Return the year, zero-based month, day of the month, and day of the week in local time |
.getHours(), .getMinutes() |
Instance method | Return the hour and minute in local time. Each local getter has a UTC twin, such as .getUTCHours() |
.setFullYear(), .setMonth(), .setDate() |
Instance method | Change the date in place and return the new timestamp. Each has a UTC twin, such as .setUTCDate() |
.getTimezoneOffset() |
Instance method | Returns the difference in minutes between UTC and the host’s local time for that date |
.toISOString() |
Instance method | Returns the date as an ISO 8601 string in UTC |
.toJSON() |
Instance method | Returns the .toISOString() string, or null for an invalid date, so JSON.stringify() serializes dates as ISO strings |
.toLocaleString() |
Instance method | Returns a language-sensitive string, optionally in a given time zone |
Examples
A support dashboard shows how long a ticket stayed open. Subtracting one date from another converts both to timestamps and returns the difference in milliseconds:
> const opened = new Date("2026-10-28T09:00:00Z");
undefined
> const closed = new Date("2026-11-04T15:30:00Z");
undefined
> closed - opened
628200000
> (closed - opened) / (1000 * 60 * 60 * 24)
7.270833333333333
A team calendar stores each meeting as one UTC moment and shows it to people in different cities. Passing a timeZone option to .toLocaleString() formats the same timestamp through Intl for each zone:
> const standup = new Date("2026-11-10T14:00:00Z");
undefined
> const options = { dateStyle: "medium", timeStyle: "short" };
undefined
> standup.toLocaleString("en-GB", { ...options, timeZone: "America/New_York" })
'10 Nov 2026, 09:00'
> standup.toLocaleString("en-GB", { ...options, timeZone: "Asia/Tokyo" })
'10 Nov 2026, 23:00'
A billing job sets a renewal date thirty days after a signup. The setters roll overflowing values into the next unit, so adding days to .getUTCDate() crosses month boundaries:
> const renewal = new Date("2026-01-20T00:00:00Z");
undefined
> renewal.setUTCDate(renewal.getUTCDate() + 30);
1771459200000
> renewal.toISOString()
'2026-02-19T00:00:00.000Z'
Common Gotchas
Months are zero-based in the component form, while days start at one. The arguments 2026, 1, 14 mean February 14:
> new Date(2026, 1, 14).toDateString()
'Sat Feb 14 2026'
The same rollover that makes date math work also moves month-end dates. Setting January 31 to February gives February 31, which rolls over to March 3:
> const due = new Date("2026-01-31T00:00:00Z");
undefined
> due.setUTCMonth(1);
1772496000000
> due.toISOString()
'2026-03-03T00:00:00.000Z'
Pick a start day and a monthIndex below to see which days fit in the target month and which roll over into the next one:
An unparsable string doesn’t throw. It creates an invalid date whose timestamp is NaN, and the error only surfaces later, when .toISOString() throws a RangeError:
> const parsed = new Date("next Tuesday");
undefined
> parsed.getTime()
NaN
> parsed.toISOString()
Uncaught RangeError: Invalid time value
at Date.toISOString (<anonymous>)
ISO strings without an offset also follow two different rules. A date-only string such as "2026-03-15" is read as UTC, but a date-time string such as "2026-03-15T09:00" is read as local time.
Related Resources
Course
JavaScript Dates and Times for Pythonistas
Port a physio clinic's Python reminder script to JavaScript, and learn to read older Date code, then use Temporal for time zones, durations, and formatting times for people.
For additional information on related topics, take a look at the following resources:
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 15, 2026