setMonth method
The setMonth method allows you
to change the month value of the
date object.
It takes the month as the first parameter
and the day of the month as the second
optional parameter.
Syntax
date.setMonth(month, [day]);
Example
Let's set the month for the current date:
let date = new Date();
date.setMonth(1);
console.log(date);
Example
Let's set the month and day for the current date:
let date = new Date();
date.setMonth(1, 25);
console.log(date);
See also
-
the
setFullYearmethod
that sets the year -
the
setDatemethod
that sets the day of the month -
the
setHoursmethod
that sets the hours -
the
setMinutesmethod
that sets the minutes -
the
setSecondsmethod
that sets the seconds -
the
setMillisecondsmethod
that sets the milliseconds