Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Date and Intl

The Date constructor

Reference for the JavaScript Date constructor: create dates from the current time, timestamps, ISO strings or year-month-day parts, with the traps explained.

new Date() creates a Date object, which represents a single moment in time. Internally it is just a number: the milliseconds since midnight UTC on January 1, 1970. All the year, month and hour values you read from a date are calculated from that number.

The constructor has several forms. With no arguments you get the current moment. With one argument you pass a timestamp, a date string or another Date. With two or more numbers you pass the parts of a date in local time.

JavaScript
new Date();                   // now
new Date(0);                  // from a timestamp
new Date("2026-03-15T09:30:00Z"); // from a string
new Date(2026, 2, 15, 9, 30); // from parts (March 15, local time)

Try it

JS Four ways to create a date

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Overflow, short years and invalid dates

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
new Date()
new Date(value)
new Date(dateString)
new Date(year, monthIndex)
new Date(year, monthIndex, day, hours, minutes, seconds, milliseconds)
Name Description
value A timestamp in milliseconds since the epoch, or an existing Date (which is copied).
dateString A string to parse. Only the ISO 8601 format is guaranteed to work in every engine.
year The full year. A value from 0 to 99 is treated as 1900 to 1999.
monthIndex The month, starting at 0 (January is 0, December is 11).
day Day of the month, starting at 1. Defaults to 1.
hours, minutes, seconds, milliseconds The time parts. Each defaults to 0.

Return value: a new Date object. If the input cannot be turned into a valid time, the result is an Invalid Date whose getTime() is NaN.

Exceptions: none for bad input; you get an Invalid Date instead.

Usage notes

  • The parts form uses local time, while a timestamp and a Z string use UTC. The same moment can therefore show different hours on different computers.
  • Date-only strings are UTC. new Date("2026-03-15") is midnight UTC, which is still March 14 in the Americas. A date-time string without a zone, such as "2026-03-15T00:00", is local.
  • Out-of-range parts roll over instead of failing: month 12 is January of the next year, day 0 is the last day of the previous month.
  • Month numbers start at 0, but days start at 1. This is the most common source of off-by-one bugs.
  • Passing a Date copies it. Dates are mutable objects, so copy before you change one that other code uses.
  • Date() without new ignores its arguments and returns the current time as a string.
  • Check validity with Number.isNaN(date.getTime()). Comparing an Invalid Date with anything is always false.
  • For new code that needs time zones, calendars or exact calendar dates, consider Temporal where it is available.

Browser support

The Date constructor works in every browser and runtime. Parsing of non-ISO strings varies between engines, so stick to ISO format.