返回到:JavaScript对象:JavaScript Date 对象
setUTCMonth() 方法用于根据世界时 (UTC) 来设置月份。
注意: 0(一月) ~ 11(十二月)
这个方法可以适用于设置月份的某一天。
提示:协调世界时,又称世界统一时间,世界标准时间,国际协调时间,简称UTC( Universal Coordinated Time ) 。
所有主要浏览器都支持 setUTCMonth() 方法
Date.setUTCMonth(month,day)
参数 | 描述 |
---|---|
month | 必需。要给 dateObject 设置的月份字段的值,用世界时表示。 该参数是 0(一月) ~ 11(十二月) 之间的整数: -1 为上一年的最后一月。 12 为下一年的第一个月。 13 为下一年的第二月。 |
day | 可选。月份中的某一天。 在 1 ~ 31 之间的整数,用作 date Object 的天字段,用世界时表示。 0 为上一个月的最后一小时。 -1 为上一个月最后一小时之前的小时时间。 如果当月有31天:32 为下一个月的第一天。 如果当月有30天:32 为下一个月的第二天。 |
Type | 描述 |
---|---|
Number | 调整过的日期的毫秒表示。 |
JavaScript 版本: | 1.3 |
---|
DEMO1:将月份设置为 4 (4月份)。
<!DOCTYPE html> <html> <title>Web176教程(Web176.com)</title> <body> <p id="demo">Click the button to display the date after changing the month.</p> <button >
DEMO2:设置月份为 4 (4月份) 日期为20号。
<!DOCTYPE html> <html> <title>Web176教程(Web176.com)</title> <body> <p id="demo">Click the button to display the date after changing the month and day.</p> <button >
DEMO3:设置日期为上一个月的最后一天。
<!DOCTYPE html> <html> <title>Web176教程(Web176.com)</title> <body> <p id="demo">Click the button to display the date after setting the date to be the last day of last month.</p> <button >