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

Méthode setMonth() en JavaScript

 JavaScript Date Object

setMonth()Méthode pour définir le mois de l'objet Date.

Si les paramètres spécifiés dépassent les limites prévues (de 0 à11) alorssetMonth()Tentez de mettre à jour les informations de date de l'objet Date de manière correspondante.

Par exemple, si vous allez15Utilisémonth(Month)The value, the year will increase1, while3Will 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 to 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 to11An integer between
day(Optional)1to31An integer 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 to see‹/›

 JavaScript Date Object