CKTIS / JavaScript
Date.prototype.getFullYear: full local year
getFullYear returns the full year number computed in local time, without the historical 1900 offset.
Version: ECMAScript 1 onward; example target: Node.js 24.22.2
Syntax
date.getFullYear()date.getFullYear() returns the local year as a Number, for example 2024. Unlike the deprecated getYear(), it does not subtract 1900. The time zone matters near a year boundary; use getUTCFullYear() for the UTC year. Year 0 and negative years are allowed by the ECMAScript time model.
The method takes no arguments, does not mutate the date, and ignores extra arguments. It returns NaN for an invalid Date. A receiver without Date internal state, such as Date.prototype.getFullYear.call({}), throws TypeError.
Use it to group or display a local calendar year, remembering that a year number without month, day, and zone does not identify an instant. The method has existed since ECMAScript 1.
Examples
const date = new Date(1999, 11, 31, 12);
console.log(date.getFullYear());
date.setFullYear(2000);
console.log(date.getFullYear(), date.getMonth(), date.getDate());
console.log(Number.isNaN(new Date(NaN).getFullYear()));Result
1999 2000 11 31 true