aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html
blob: 7c4cf29b9af292a2fbbfbc5c69c54fa75fea6b43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: Date.prototype.getFullYear()
slug: Web/JavaScript/Reference/Global_Objects/Date/getFullYear
tags:
  - Date
  - JavaScript
  - Method
  - Prototype
  - Reference
translation_of: Web/JavaScript/Reference/Global_Objects/Date/getFullYear
---
<p>{{JSRef}}</p>

<p><strong><code>getFullYear()</code></strong> 方法根据本地时间返回指定日期的年份。</p>

<p>此方法替代 {{jsxref("Date.prototype.getYear()", "getYear()")}}</p>

<div>{{EmbedInteractiveExample("pages/js/date-getfullyear.html")}}</div>



<h2 id="Syntax" name="Syntax">语法</h2>

<pre style="margin-bottom: 0px; padding: 1em; border-left-width: 6px; border-left-style: solid; font-family: Consolas, Monaco, 'Andale Mono', monospace; font-size: 14px; text-shadow: none; direction: ltr; white-space: normal; background-color: rgba(212, 221, 228, 0.498039);"><code class="language-html" style="font-family: Consolas, Monaco, 'Andale Mono', monospace; color: inherit; text-shadow: none; direction: ltr;">dateObj.getFullYear()</code>
</pre>

<h3 id="Description" name="Description">返回值</h3>

<p>根据当地时间,返回一个对应于给定日期的年份数字。</p>

<h2 id="描述">描述</h2>

<p><code>getFullYear()</code>返回的值是绝对数。 对于1000到9999之间的日期,<code>getFullYear()</code>返回一个四位数字,如1995。使用此函数确保在2000年后兼容。</p>

<h2 id="Examples" name="Examples">例子</h2>

<h3 id="Example:_Using_getFullYear" name="Example:_Using_getFullYear">使用<code>getFullYear()</code></h3>

<p>下面的例子将当前年份的四位数值分配给变量<code>year</code></p>

<pre class="brush: js">var today = new Date();
var year = today.getFullYear();
</pre>

<h2 id="规范" style="margin-bottom: 20px; line-height: 30px;">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES1')}}</td>
   <td>{{Spec2('ES1')}}</td>
   <td>Initial definition. Implemented in JavaScript 1.3.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.9.5.10', 'Date.prototype.getFullYear')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-date.prototype.getfullyear', 'Date.prototype.getFullYear')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-date.prototype.getfullyear', 'Date.prototype.getFullYear')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性" style="margin-bottom: 20px; line-height: 30px;">浏览器兼容性</h2>

<p>{{Compat("javascript.builtins.Date.getFullYear")}}</p>

<h2 id="See_Also" name="See_Also" style="margin-bottom: 20px; line-height: 30px;">相关链接</h2>

<ul>
 <li>{{jsxref("Date.prototype.getUTCFullYear()")}}</li>
 <li>{{jsxref("Date.prototype.setFullYear()")}}</li>
 <li>{{jsxref("Date.prototype.getYear()")}}</li>
</ul>