setFullYear method
The setFullYear method allows
you to change the year value for the
date object.
It takes a year as the first parameter,
it can also take a month and a day.
Syntax
date.setFullYear(year, [month], [day]);
Example
Let's change the year in the date object:
let date = new Date();
date.setFullYear(2026);
console.log(date.getFullYear());
The code execution result:
2026
Example
Let's change the year, month, and day at once:
let date = new Date();
date.setFullYear(2026, 5, 6);
See also
-
the
setMonthmethod
that sets the month -
the
setDatemethod
that sets the day of the month -
the
setHoursmethod
that sets the hours -
the
setMinutesmethod
that sets the minutes -
the
setSecondsmethod
that sets the seconds