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

javascriptdate.setMonth(month, [day]);

Example

Let's set the month for the current date:

javascriptlet date = new Date();
date.setMonth(1);

console.log(date);

Example

Let's set the month and day for the current date:

javascriptlet date = new Date();
date.setMonth(1, 25);

console.log(date);

See also