Date.prototype.setFullYear() changes the year of an existing Date in local time. It can also set the month and day in the same call, mutates the Date object, normalizes out-of-range values, and returns the updated timestamp.
Syntax:
date.setFullYear(year);
date.setFullYear(year, monthValue);
date.setFullYear(year, monthValue, dateValue);
A simple year change:
const date = new Date(2026, 8, 10);
date.setFullYear(2030);
console.log(date.getFullYear()); // 2030
When only the year is supplied, the current month, day and time components remain in place where possible.
const date = new Date(2026, 3, 5, 9, 30);
date.setFullYear(2015);
console.log(date.toString());
The optional second and third arguments use the same rules as the numeric Date constructor: months are zero-based and the day is the day of the month.
const date = new Date();
date.setFullYear(2028, 1, 29); // 29 Feb 2028
console.log(date.toDateString());
Read the current year with getFullYear(), then set the adjusted year.
const date = new Date();
date.setFullYear(date.getFullYear() + 10);
console.log(date);
Be careful when adding years to a leap-day date. If the target year does not have February 29, JavaScript normalizes the result into March.
const leapDay = new Date(2028, 1, 29);
leapDay.setFullYear(2029);
console.log(leapDay.toDateString()); // Thu Mar 01 2029
If your business rule means “last valid day of February,” detect and clamp that case explicitly.
Optional month/day values are normalized. Month 12 becomes January of the next year; day 0 means the final day of the previous month.
const date = new Date(2026, 0, 15);
date.setFullYear(2026, 12, 1);
console.log(date.toDateString()); // Fri Jan 01 2027
const date = new Date();
const timestamp = date.setFullYear(2035);
console.log(typeof timestamp); // "number"
console.log(date.getFullYear()); // 2035
setFullYear() interprets the components in local time. Use setUTCFullYear() when your calculation is defined in UTC.
const date = new Date("2026-12-31T23:30:00Z");
date.setUTCFullYear(2030);
console.log(date.toISOString());
Use setFullYear() for modern code. The older setYear() method has legacy handling for years 0–99 and should not be used for new work.
Next: setHours() Date Reference
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.