offline version v3


133 of 264 menu

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 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
enru