setters

Date.prototype.setFullYear

Mutates the Date in place, setting the year (and optionally month and day) in LOCAL time, and returns the new timestamp in milliseconds. The parallel setters setMonth, setDate, setHours, setMinutes, setSeconds, setMilliseconds follow the same in-place mutation pattern.

date.setFullYear(year[, month[, date]])

Parameters

Parameter Purpose
year 4-digit year
month optional 0-11 month
date optional 1-31 day of month
return value the resulting getTime() (ms since epoch)

Examples

const d = new Date('2026-07-19'); d.setFullYear(2030); console.log(d.getUTCFullYear()); // 2030

mutates in place

const d = new Date(2026, 0, 31); d.setMonth(1); console.log(d.toDateString()); // spills into March

setMonth: Feb 31 -> Mar 3

const d = new Date('2026-07-19'); d.setDate(d.getDate() + 7); console.log(d.toISOString()); // one week later

add days by overflow

const d = new Date(); d.setHours(0,0,0,0); console.log(d.toString()); // start of local day

setHours accepts h, m, s, ms

Gotcha

Setters MUTATE the original Date - clone with new Date(d) first if you need to keep the old value. Overflow is silently normalized (setMonth(12) becomes January of the next year).

Related

← All JS Date methods · Math methods · Cron syntax