Date.prototype.getFullYear()

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
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
getFullYear 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

相关链接