Local getters
Read components in the device local time zone.
Date get and set methods read or change components. The important trap: setters mutate the existing Date object.
const date = new Date("2026-01-15T09:30:00Z");
date.getUTCFullYear();
date.getUTCMonth(); // 0 for January
date.setUTCDate(20);
Dates, Time & Intl
Date has local getters such as getFullYear, getMonth and getDate. It also has UTC getters such as getUTCFullYear, getUTCMonth and getUTCDate.
Months are zero-based in Date getters and setters. January is 0, February is 1 and December is 11. Day of month uses normal one-based numbering.
Setters modify the existing Date object. If you need a changed copy, create a new Date first and then set the copy.
Read components in the device local time zone.
Read components in UTC.
getMonth returns 0-11, not 1-12.
setDate, setMonth and setFullYear change the Date object.
Examples
const original = new Date("2026-01-15T09:30:00Z");
const changed = new Date(original.getTime());
changed.setUTCDate(20);
const original = new Date("2026-01-15T09:30:00Z");
original.setUTCDate(20);
// Code that still needs January 15 has now lost it.
Code patterns
Dates and time zones become much easier when every example names the concept it represents: instant, local display, UTC output, calendar date, formatted text or zoned time.
Use UTC methods when the date should not depend on the device zone.
const date = new Date("2026-01-15T09:30:00Z");
console.log(date.getUTCFullYear());
console.log(date.getUTCMonth() + 1);
console.log(date.getUTCDate());
Use local methods only when local display logic is intended.
const date = new Date("2026-01-15T09:30:00Z");
console.log(date.getFullYear());
console.log(date.getMonth() + 1);
console.log(date.getDate());
Avoid mutating a Date that other code still needs.
const original = new Date("2026-01-15T09:30:00Z");
const copy = new Date(original.getTime());
copy.setUTCDate(20);
console.log(original.toISOString());
console.log(copy.toISOString());
Use a copy and setDate for simple calendar-day movement.
const start = new Date("2026-01-15T09:30:00Z");
const next = new Date(start.getTime());
next.setUTCDate(next.getUTCDate() + 7);
console.log(next.toISOString());
Rules that matter
Date-time bugs usually start when storage format, calculation logic and user-facing display are treated as the same thing. Keep those responsibilities separate and the code becomes much easier to trust.
Do not mix getDate and getUTCDate casually.
Date months are zero-based.
Setters mutate the Date object.
Setting dates can roll into another month.
Getters are for logic, not polished human formatting.
Date setters can become fragile for advanced cases.
Production thinking
Date getters and setters are low-level. They work, but the local/UTC split and mutation behavior create many subtle bugs.
Calendar values should be displayed clearly after calculation. Do not expose zero-based month values to users.
Production code should isolate Date mutation and avoid sharing mutable Date objects between unrelated logic.
Generated date values should not accidentally shift month or day because of local/UTC confusion.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Dates are full of traps. Explain the concept first, then run the code and check whether the output matches your mental model.