getFullYear method
The getFullYear method is applied to the
date object
and returns the year consisting of 4 digits.
Syntax
date.getFullYear();
Example
Let's get the current year:
let date = new Date();
let res = date.getFullYear();
console.log(res); // outputs the current year
Example
In this example, the selected year will be displayed:
let date = new Date(2025, 11, 31);
let res = date.getFullYear();
console.log(res);
The code execution result:
2025
See also
-
the
getMonthmethod
that gets the month -
the
getDatemethod
that gets the day of the month -
the
getHoursmethod
that gets the hours -
the
getMinutesmethod
that gets the minutes -
the
getSecondsmethod
that gets the seconds