JavaScript setMonth () method
Definition and Usage
setMonth () method is used to set the month.
Note: Jan is 0, Dec 11
This method can be used to set the day of the month.
Browser Support
All major browsers support setMonth () method
grammar
Date.setMonth( month , day )
Parameter Value
参数 | 描述 |
---|---|
month | 必需。一个表示月份的数值。
该值介于 0(一月) ~ 11(十二月) 之间:
|
day | 可选。一个表示月的某一天的数值,
该值介于 1 ~ 31 之间(以本地时间计):
如果当月有31天:
如果当月有30天:
|
return value
Type | 描述 |
---|---|
Number | 返回1970年一月一日午夜至调整过的日期的毫秒表示。在 ECMAScript 标准化之前,该方法什么都不返回 |
technical details
JavaScript version: | 1.0 |
---|
More examples
Examples
Set the date for the last day of the previous month:
var d = new Date();
d.setMonth(d.getMonth(),0);
d.setMonth(d.getMonth(),0);
d output:
try it"