getters
Date.prototype.getFullYear
Returns the 4-digit year of the date according to LOCAL time. Prefer this over the deprecated getYear(), which returns year-1900.
date.getFullYear() Parameters
| Parameter | Purpose |
|---|---|
| () | no arguments; returns Number |
| local time | uses the host's local timezone; use getUTCFullYear for UTC |
Examples
console.log(new Date('2026-07-19T12:00:00Z').getFullYear()); // 2026 local-year of a UTC instant
console.log(new Date(0).getUTCFullYear()); // 1970 UTC counterpart
const d = new Date(); console.log(d.getFullYear()); // current year today's year
Gotcha
Returns the LOCAL-timezone year; near midnight on New Year's Eve/Day this can differ from the UTC year.
Related
Date.prototype.getUTCFullYear / getUTCMonth / getUTCDate / getUTCHours
The UTC-flavored getters mirror their local counterparts but read fields in Coordinated Universal Time, ignoring the host timezone. Use them whenever you need timezone-stable output such as logs, database keys, or ISO output.
Date.prototype.getMonth
Returns the month of the date in LOCAL time as an integer from 0 (January) to 11 (December). This zero-based indexing is the single most common source of off-by-one date bugs in JavaScript.
Date.prototype.setFullYear
Mutates the Date in place, setting the year (and optionally month and day) in LOCAL time, and returns the new timestamp in milliseconds. The parallel setters setMonth, setDate, setHours, setMinutes, setSeconds, setMilliseconds follow the same in-place mutation pattern.
Date.prototype.getDate
Returns the day of the month (1-31) in LOCAL time. Do not confuse this with getDay, which returns the weekday.
Date.prototype.getDay
Returns the weekday of the date in LOCAL time as an integer from 0 (Sunday) to 6 (Saturday). Named confusingly close to getDate but returns something completely different.