Date.prototype.setUTCFullYear()
Date 实例的 setUTCFullYear() 方法根据世界时间更改该日期的年份。
¥The setUTCFullYear() method of Date instances changes the year for this date according to universal time.
Try it
语法
参数
¥Parameters
yearValue-
代表年份的整数。例如,1995 年。
monthValueOptional-
代表月份的整数:0 代表一月,1 代表二月,依此类推。
dateValueOptional-
1 到 31 之间的整数,表示月份中的第几天。如果指定
dateValue,则还必须指定monthValue。
返回值
¥Return value
就地更改 Date 对象,并返回其新的 timestamp。如果参数为 NaN(或获取 coerced 到 NaN 的其他值,例如 undefined),则日期设置为 失效日期,并返回 NaN。
¥Changes the Date object in place, and returns its new timestamp. If a parameter is NaN (or other values that get coerced to NaN, such as undefined), the date is set to Invalid Date and NaN is returned.
描述
¥Description
如果不指定 monthValue 和 dateValue 参数,则使用从 getUTCMonth() 和 getUTCDate() 方法返回的值。
¥If you do not specify the monthValue and
dateValue parameters, the values returned from the
getUTCMonth() and
getUTCDate() methods are used.
如果你指定的参数超出预期范围,setUTCFullYear() 会尝试相应更新 Date 对象中的其他参数和日期信息。例如,如果为 monthValue 指定 15,则年份将增加 1 (yearValue + 1),月份将使用 3。
¥If a parameter you specify is outside of the expected range,
setUTCFullYear() attempts to update the other parameters and the date
information in the Date object accordingly. For example, if you specify 15
for monthValue, the year is incremented by 1
(yearValue + 1), and 3 is used for the month.
示例
使用 setUTCFullYear()
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-date.prototype.setutcfullyear |
浏览器兼容性
BCD tables only load in the browser