setUTCMonth()方法根据通用的时间来设置一个准确的月份
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
语法
dateObj.setUTCMonth(monthValue[, dayValue])
参数
-
monthValue
- 一个0-11的整数,代表1月到12月。
-
dayValue
- 可选参数:一个1-31的整数,代表一个月的天数。
返回值
这个数值是从1970年1月1号 00:00:00到当前时间的毫秒数(国际通用时间)
描述
如果你没有明确书写dayValue
这个参数,那么就会从getUTCDate()
方法返回对应的数值.
如果你写了一个超过在规定的范围内的参数. setUTCMonth()就会试图相应的更新时间信息在Data对象中。例如,如果你用15作为
monthValue的值,那么年份就会加1,并且月份会变成3.(15=12+3)
示例
使用 setUTCMonth()
var theBigDay = new Date(); theBigDay.setUTCMonth(11);
规范
规范 | 状态 | 注释 |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | 最初定义并使用在javascript 1.3版本中 |
ECMAScript 5.1 (ECMA-262) Date.prototype.setUTCMonth |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) Date.prototype.setUTCMonth |
Standard | |
ECMAScript Latest Draft (ECMA-262) Date.prototype.setUTCMonth |
Draft |
浏览器兼容性
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
setUTCMonth |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Legend
- Full support
- Full support