Loading lesson path
Concept visual
Start at both ends
Set Date methods let you set date values (years, months, days, hours, minutes, seconds, milliseconds) for a Date Object.Set Date methods are used for setting a part of a date:
Formula
Set the day as a number (1 - 31)setFullYear() Set the year (yyyy) setHours()
Formula
Set the hour (0 - 23)setMilliseconds()
Formula
Set the milliseconds (0 - 999)setMinutes()
Formula
Set the minutes (0 - 59)setMonth()
Formula
Set the month (0 - 11)setSeconds()
Formula
Set the seconds (0 - 59)setTime() Set the time (milliseconds since January 1, 1970)
method sets the year of a date object. In this example to 2020:
const d = new Date("January 01, 2025");
d.setFullYear(2020);method can optionally set month and day:
const d = new Date("January 01, 2025");
d.setFullYear(2020, 11, 3);Formula
method sets the month of a date object (0 - 11):const d = new Date("January 01, 2025");
d.setMonth(11);Formula
method sets the day of a date object (1 - 31):const d = new Date("January 01, 2025");
d.setDate(15);method can also be used to add days to a date:
const d = new Date("January 01, 2025");
d.setDate(d.getDate() + 50);If adding days shifts the month or year, the changes are handled automatically by the Date object.
Formula
method sets the hours of a date object (0 - 23):const d = new Date("January 01, 2025");
d.setHours(22);method can also be used to set minutes and seconds.
const d = new Date("January 01, 2025");
d.setHours(22, 10, 20);Formula
method sets the minutes of a date object (0 - 59):