Date

An object representing a specific moment in time, with methods to read and change the date and time.

Returns
A new Date object.
On this page

Example

#
JavaScript
const exam = new Date(Date.UTC(2026, 8, 28, 10, 30))

console.log(exam)
console.log(exam.getUTCFullYear(), exam.getUTCMonth(), exam.getUTCDate())
console.log(exam.getUTCDay(), exam.getUTCHours())
Console
2026-09-28T10:30:00.000Z
2026 8 28
1 10

Month 8 is September, because months are counted from zero. Weekday 1 means Monday (Sunday is 0).

Definition and usage

#

A Date object stores a single point in time as the number of milliseconds that have passed since January 1, 1970 (UTC). new Date() with no arguments returns the current moment, and Date.now() returns just the number of milliseconds, handy for measuring time.

You can create a date from a number of milliseconds, from a string in ISO format ("2026-09-28T10:30:00Z"), or from separate components: new Date(year, month, day, hour, minute). Watch out: months are counted from zero, so January is 0 and December is 11.

Methods like getFullYear(), getMonth(), getDate(), getDay(), and getHours() return components in the user’s own time zone, while their UTC counterparts, such as getUTCHours(), use universal time. To display dates in a readable, localized form, use toLocaleDateString() or Intl.DateTimeFormat.

Date objects are mutable: the set...() methods modify the existing object. You can calculate the difference between dates by subtracting them, since the result is a number of milliseconds.

Syntax

#
Syntax
new Date()
new Date(milliseconds)
new Date(dateString)
new Date(year, monthIndex, day, hours, minutes, seconds)

Date.now()
Date.UTC(year, monthIndex, day, hours, minutes)

Parameters

#
  • milliseconds

    number

    The number of milliseconds since January 1, 1970 (UTC).
  • dateString

    string

    A date in ISO format, e.g. "2026-09-28" or "2026-09-28T10:30:00Z".
  • year, monthIndex, day…

    numbers

    Date components in the local time zone. monthIndex takes values from 0 (January) to 11 (December).

More examples

#
Months counted from zero
JavaScript
const start = new Date(2026, 0, 1)
const oops = new Date(2026, 1, 1)

console.log(start.getMonth(), start.getDate())
console.log(oops.toLocaleDateString('en-US', { month: 'long' }))
Console
0 1
February
Difference between dates in days
JavaScript
const start = new Date('2026-09-01T00:00:00Z')
const end = new Date('2026-09-28T00:00:00Z')

const days = (end - start) / (1000 * 60 * 60 * 24)
console.log(days)
Console
27
A deadline a week later
JavaScript
const deadline = new Date(Date.UTC(2026, 8, 28))
deadline.setUTCDate(deadline.getUTCDate() + 7)

console.log(deadline)
Console
2026-10-05T00:00:00.000Z

The set...() methods automatically roll extra days over into the next month, so September 28 plus 7 days gives October 5.

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Remember that months are counted from zero: new Date(2026, 0, 1) is January 1st, not February 1st.
  • Store and send dates in ISO format (toISOString()), and convert to a local form only when displaying them.
  • A string with just a date, e.g. "2026-09-28", is treated as UTC time, while a string with a time but no Z at the end is treated as local time. This is a common cause of multi-hour offsets.

Related entries

#

Spotted a mistake or missing an example? Write to us.