English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript setMonth() method

 JavaScript Date Object

setMonth()Method to set the month of the date object.

If the parameter you specify is out of the expected range (from 0 to11),thensetMonth()Try to update the date information in the Date object accordingly.

For example, if you will15Used formonth(Month)Value, the year will increase1, and3Will be used as the month.

This method can also be used to set the day of the month.

Syntax:

date.setMonth(month, day)
var d = new Date();
d.setMonth(11);
Test and See‹/›

If not specifieddayIf the parameter is not specified,

Browser Compatibility

All browsers fully support the setMonth() method:

Method
setMonth()IsIsIsIsIs

Parameter Value

ParameterDescription
month(Required) 0 to11Integer between
day(Optional)1to31Integer between

Technical Details

Return Value:1970 Year1Month1Milliseconds between 00:00:00 UTC and the update date
JavaScript Version:ECMAScript 1

More Examples

Specify16As the month value:

var d = new Date();
d.setMonth(16);
Test and See‹/›

 JavaScript Date Object