Favorites

JavaScript Date Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Date
JavaScript Numbers and Dates · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

Date objects represent a single moment in time. They let you get the current date and time, read and change parts of a date, and format dates for display.

Description

A Date object represents a single moment in time, stored as the number of milliseconds since 1 January 1970 UTC (the Unix epoch). new Date() gives the current date and time; you can also create one from a timestamp, a date string or separate year, month and day values. Note that months are counted from 0, so January is 0 and December is 11.

Getter and setter methods such as getFullYear() and setDate() work in the user's local time zone, and the getUTC...() versions work in UTC. For display, toLocaleDateString() and Intl.DateTimeFormat format dates for any language. Parsing strings other than the ISO format (2026-11-28T10:00:00Z) is unreliable across browsers. The newer Temporal API addresses many of Date's problems where it is supported.

Dates are stored as a single number, so comparing two dates or finding the difference between them is just subtraction: date2 - date1 gives milliseconds. Adding days is easiest with setDate(getDate() + n), which handles month and year boundaries for you. Invalid dates, such as new Date('nonsense'), don't throw; they return an object whose time is NaN, which you can check with isNaN(date).

Creating

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

Static methods

NameDescription
Date.now()The Date.now() static method returns the current time as the number of milliseconds since 1 January 1970 UTC.
Date.parse()The Date.parse() static method converts a date string to a timestamp.

Instance methods

NameDescription
Date.prototype.getDate()The getDate() method returns the day of the month (1 to 31) of a date.
Date.prototype.getDay()The getDay() method returns the day of the week of a date, from 0 (Sunday) to 6 (Saturday).
Date.prototype.getFullYear()The getFullYear() method returns the year of a date, as a four-digit number, in local time.
Date.prototype.getHours()The getHours() method returns the hour of a date, from 0 to 23.
Date.prototype.getMonth()The getMonth() method returns the month of a date as a number from 0 (January) to 11 (December).
Date.prototype.getTime()The getTime() method returns a date's timestamp: milliseconds since 1 January 1970 UTC.
Date.prototype.setDate()The setDate() method changes the day of the month of a date.
Date.prototype.setFullYear()The setFullYear() method changes the year of a date, and optionally its month and day.
Date.prototype.toISOString()The toISOString() method returns a date as a standard ISO 8601 string in UTC, such as 2026-11-28T00:30:00.000Z.
Date.prototype.toLocaleDateString()The toLocaleDateString() method formats the date part of a Date for a given language and region, such as 28/11/2026 or November 28, 2026.
Date.prototype.toLocaleTimeString()The toLocaleTimeString() method formats the time part of a Date for a given language and region.

Example

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

const launch = new Date(2026, 11, 25);   // 25 December
console.log(launch.toDateString());
console.log(launch.getMonth());           // 11

const days = Math.ceil((launch - now) / 86400000);
console.log(days, 'days to go');
console.log(new Date(0).toISOString());

Browser Support

The following information will show you the current browser support for the Date object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee