JavaScript Date

Beginner
8 min read
Updated: Nov 2026
3 examples
Local and UTC

Definition and Usage

In JavaScript, a Date is an object that stores one moment in time. Internally that moment is a count of milliseconds since 1 January 1970 UTC. You create a date with new Date() for “now”, or with parts: new Date(2026, 0, 15).

The month argument is zero-based: 0 is January and 11 is December. getDate() is the day of the month (1–31). getDay() is the weekday, and that index starts at 0 for Sunday. Setters such as setDate() change the same object. toISOString() prints a UTC string for APIs.

This page teaches what a Date is. The Date Methods index and Date Properties index list every method and property guide (getFullYear(), toISOString(), constructor, and more).

Month 0 is January.

new Date(2026, 0, 15) is 15 January 2026 in local time. getMonth() returns 0 for that date.

JavaScript Syntax

Common ways to create and read a date:

JavaScript
const now = new Date();                 // this moment
const birthday = new Date(2026, 0, 15); // 15 Jan 2026, local
const year = birthday.getFullYear();    // 2026
const month = birthday.getMonth();      // 0  (January)
const stamp = Date.now();               // ms since the epoch
const utc = birthday.toISOString();     // UTC text for APIs

Core Ideas

Ideas every JavaScript Date tutorial builds on:

IdeaExampleRemember
Createnew Date(2026, 0, 15)Local date; month starts at 0
MonthgetMonth()0 = January, 11 = December
WeekdaygetDay()0 = Sunday … 6 = Saturday
UTCDate.UTC(2026, 0, 15)Build a timestamp in UTC
API texttoISOString()Always a UTC string
ChangesetDate(20)Mutates that Date object

JavaScript Examples

Three short programs that show how Date works in a JS tutorial.

Example 1 — Read year, month, day, and weekday

15 January 2026 in local time. The month index is 0.

JavaScript
const birthday = new Date(2026, 0, 15);

console.log(birthday.getFullYear());
console.log(birthday.getMonth());
console.log(birthday.getDate());
console.log(birthday.getDay());

How It Works

  1. getFullYear() returns 2026.
  2. getMonth() returns 0 because January is month 0.
  3. getDate() is the day of the month, 15. getDay() is 4 (Thursday).

Example 2 — Build a UTC instant

Date.UTC ignores the local timezone. toISOString() prints that instant.

JavaScript
const utc = new Date(Date.UTC(2026, 0, 15));

console.log(utc.getUTCFullYear());
console.log(utc.getUTCMonth());
console.log(utc.toISOString());

How It Works

  1. Date.UTC(2026, 0, 15) is midnight at the start of 15 January 2026 UTC.
  2. getUTCMonth() is still 0 for January.
  3. toISOString() ends in Z, which means UTC.

Example 3 — Setters change the same object

Copy with getTime() before you change a second date.

JavaScript
const d = new Date(2026, 0, 15);
d.setDate(20);
console.log(d.getDate());

const copy = new Date(d.getTime());
copy.setMonth(5);
console.log(d.getMonth());
console.log(copy.getMonth());

How It Works

  1. setDate(20) changes d in place, so getDate() is 20.
  2. new Date(d.getTime()) copies that moment into copy.
  3. setMonth(5) changes only the copy. 5 is June. d stays in January (0).

Next: Methods & Properties Indexes

After you know what a Date is, open the indexes for full tutorials on every essential Date API in this JavaScript series.

Start withWhy
getFullYear()Read the four-digit year
getMonth()Month index, January is 0
toISOString()UTC text for APIs and JSON
Date.now()Current timestamp without a Date object

Full lists: Date Methods index and Date Properties index.

Frequently Asked Questions

A Date is an object that stores one moment as milliseconds since 1 January 1970 UTC (the Unix epoch). You create it with new Date() or new Date(year, month, day), then read parts with getters such as getFullYear().
Months are zero-based: 0 is January and 11 is December. Days of the month from getDate() are 1–31. getDay() is also zero-based, but that index is the weekday: 0 is Sunday.
Yes. setDate(), setMonth(), and the other setters change the same object and return the new timestamp. Copy first with new Date(date.getTime()) when you need to keep the original moment.
getHours() and setHours() use the local timezone. getUTCHours() and Date.UTC() use Coordinated Universal Time. toISOString() always prints UTC, which is the usual form for APIs.
Practice the examples here, then open the Date Methods index for getFullYear(), getMonth(), toISOString(), and Date.now(). The Date Properties index lists constructor, prototype, length, and name.

Browse every Date method

Open the index for getFullYear(), toISOString(), Date.now(), and the rest.

Date Methods index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful