Prototype Setters and Getters

Most Date methods follow the pattern get|set + optional UTC + FullYear | Month | Date | Hours | Minutes | Seconds | Milliseconds. Without UTC they use the local time zone. getDay() gives the weekday (0 is Sunday), getTime() and setTime() read and write the timestamp, and getTimezoneOffset() returns minutes behind UTC, so GMT+8 is -480. Setters mutate the object and normalize overflow, which makes date arithmetic easy.

Reading fields, adding time and validating a DateJavaScriptLive
const d = new Date(2026, 8, 15, 23, 30);   // 15 Sep 2026, 23:30 local (GMT+8)
d.setMinutes(d.getMinutes() + 45);         // overflow rolls into the next day
console.log(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes());
console.log(d.getDay(), d.getUTCDay(), d.getUTCHours(), d.getTimezoneOffset());
d.setDate(d.getDate() + 30);               // add 30 days
console.log(d.toDateString());
const isValid = x => x instanceof Date && !Number.isNaN(x.getTime());
console.log(isValid(d), isValid(new Date('not a date')), isValid('2026-09-15'));

Because setters mutate, copy a date with new Date(d) before changing it. Adding 24 * 60 * 60 * 1000 ms is not "one day" across a daylight-saving change; setDate(getDate() + 1) is.