offline version v3


134 of 264 menu

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

enru