getFullYear()
方法根据本地时间返回指定日期的年份。
此方法替代 getYear()
。
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.getFullYear()
根据当地时间,返回一个对应于给定日期的年份数字。
getFullYear()
返回的值是绝对数。 对于1000到9999之间的日期,getFullYear()
返回一个四位数字,如1995。使用此函数确保在2000年后兼容。
getFullYear()
下面的例子将当前年份的四位数值分配给变量year
。
var today = new Date();
var year = today.getFullYear();
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.3. |
ECMAScript 5.1 (ECMA-262) Date.prototype.getFullYear |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) Date.prototype.getFullYear |
Standard | |
ECMAScript Latest Draft (ECMA-262) Date.prototype.getFullYear |
Draft |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getFullYear | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 1 | IE Full support Yes | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes | nodejs Full support Yes |