Date.prototype.getFullYear
Returns the year of the specified date according to local time
Syntax
date.getFullYear()Return Value
A four-digit number representing the year
Examples
const date = new Date('2024-06-15');
console.log(date.getFullYear()); // 2024const now = new Date();
const year = now.getFullYear();
console.log(`Copyright © ${year}`);function isLeapYear(year: number) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
}
console.log(isLeapYear(new Date().getFullYear()));Understanding Date.prototype.getFullYear
The Date.prototype.getFullYear method in JavaScript returns the year of the specified date according to local time. It belongs to the Date object and is one of the most widely used methods for working with date values in modern JavaScript and TypeScript applications.
The method signature is date.getFullYear(). When called, it returns a four-digit number representing the year. Understanding when and how to use getFullYear() helps you write more expressive, readable code.
Common use cases for Date.prototype.getFullYear include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like date-getmonth, date-getdate, date-setfullyear, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Date.prototype.getFullYear is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Date.prototype.getMonthReturns the month (0-11) for the specified date according to local time
Date.prototype.getDateReturns the day of the month (1-31) for the specified date according to local time
Date.prototype.setFullYearSets the full year for a specified date according to local time and returns the updated timestamp
More Date Methods
Other methods in the Date object
Related Tools
More Date Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.