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

javascriptdate.setFullYear(year, [month], [day]);

Example

Let's change the year in the date object:

javascriptlet date = new Date();
date.setFullYear(2026);

console.log(date.getFullYear());

The code execution result:

javascript2026

Example

Let's change the year, month, and day at once:

javascriptlet date = new Date();
date.setFullYear(2026, 5, 6);

See also

  • the setMonth method
    that sets the month
  • the setDate method
    that sets the day of the month
  • the setHours method
    that sets the hours
  • the setMinutes method
    that sets the minutes
  • the setSeconds method
    that sets the seconds