Example 1 — Set the Year
Change only the local year; month and day stay the same.
const event = new Date("August 19, 1975 23:15:30");
event.setFullYear(1969);
console.log(event.getFullYear()); // 1969 How It Works
- Start with a date. August 19, 1975 is the baseline.
- Write the year.
setFullYear(1969)updates only the year. - Keep month/day. August 19 remains; only the year changes.
- Read it back.
getFullYear()returns1969.

