--- title: Date.prototype.setFullYear() slug: Web/JavaScript/Reference/Global_Objects/Date/setFullYear translation_of: Web/JavaScript/Reference/Global_Objects/Date/setFullYear ---
setFullYear() 方法根据本地时间为一个日期对象设置年份。
dateObj.setFullYear(yearValue[, monthValue[, dayValue]])
yearValuemonthValuedayValuedayValue 参数,就必须同时指定 monthValue。如果没有指定 monthValue 和dayValue 参数,将会使用 getMonth 和getDate 方法的返回值。
如果有一个参数超出了合理的范围,setFullYear 方法会更新其他参数值,日期对象的日期值也会被相应更新。 例如,为 monthValue 指定 15, 则年份会加1,月份值会为3。
setFullYear方法var theBigDay = new Date(); theBigDay.setFullYear(1997);
| 规范版本 | 规范状态 | 注解 |
|---|---|---|
| ECMAScript 1st Edition. Implemented in JavaScript 1.3 | Standard | Initial definition. |
| {{SpecName('ES5.1', '#sec-15.9.5.40', 'Date.prototype.setFullYear')}} | {{Spec2('ES5.1')}} | |
| {{SpecName('ES6', '#sec-date.prototype.setfullyear', 'Date.prototype.setFullYear')}} | {{Spec2('ES6')}} |
{{Compat("javascript.builtins.Date.setFullYear")}}