getFullYear() 方法根据本地时间返回指定日期的年份。

此方法替代 getYear()

语法

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  

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes

Legend

Full support  
Full support

相关链接

文档标签和贡献者

此页面的贡献者: fscholz, zhangchen, xqin, teoli, AlexChao, ziyunfei
最后编辑者: fscholz,