Date.prototype.setFullYear
Sets the year, and optionally the month and day.
Available since: ES1
Syntax
date.setFullYear(year, monthIndex, day)Parameters
| Parameter | Type | Description |
|---|---|---|
| year | number | The year. |
| monthIndex | number | Optional. The month from 0 to 11. |
| day | number | Optional. The day of the month. |
Return value
numberThe new timestamp. The object itself changes.
Examples
The same date a year later:
const date = new Date(2026, 2, 15);
date.setFullYear(date.getFullYear() + 1);
console.log(date.getFullYear(), date.getMonth(), date.getDate());Output:
2027 2 15Notes
Every set... method changes the object itself. If you still need the original date, copy it first: new Date(date).
See also
- Date.prototype.getFullYear — Returns the year.
- Date.prototype.setMonth — Sets the month.
- Date.prototype.setDate — Sets the day of the month — handy for adding and subtracting days.
In the tutorial
- Dates and time — The Date object in JavaScript: creating a date, reading the year, month and day, changing a date, the difference between dates and the ISO format.