`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 |

## 浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-dataand send us a pull request.

Update compatibility data on GitHub

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

### Legend

Full support
  Full support

## 相关链接

- `Date.prototype.getUTCFullYear()`
- `Date.prototype.setFullYear()`
- `Date.prototype.getYear()`