From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/date/getfullyear/index.html | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html b/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html new file mode 100644 index 0000000000..10a0870fac --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/date/getfullyear/index.html @@ -0,0 +1,89 @@ +--- +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 +--- +

{{JSRef}}

+ +

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

+ +

此方法替代 {{jsxref("Date.prototype.getYear()", "getYear()")}} 。

+ +
{{EmbedInteractiveExample("pages/js/date-getfullyear.html")}}
+ + + +

语法

+ +
dateObj.getFullYear()
+
+ +

返回值

+ +

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

+ +

描述

+ +

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

+ +

例子

+ +

使用getFullYear()

+ +

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

+ +
var today = new Date();
+var year = today.getFullYear();
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition. Implemented in JavaScript 1.3.
{{SpecName('ES5.1', '#sec-15.9.5.10', 'Date.prototype.getFullYear')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-date.prototype.getfullyear', 'Date.prototype.getFullYear')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-date.prototype.getfullyear', 'Date.prototype.getFullYear')}}{{Spec2('ESDraft')}} 
+ +

浏览器兼容性

+ + + +

{{Compat("javascript.builtins.Date.getFullYear")}}

+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf