getFullYear 方法 (Date)

使用当地时间获取年份。

语法

dateObj.getFullYear()

参数

必需的dateObj引用是Date对象。

返回值

由四位数字表示的年份。例如,1976年的返回值为1976。在Date构造函数或setFullYear中指定为两位数字的年份被假定处于20世纪,因此,对于给定的“5/14/12”,getFullYear将返回“1912”。

备注

若要根据协调世界时(UTC)获取年份,请使用getUTCFullYer方法。

示例

以下示例演示getFullYear方法的用法。

var date = new Date("1/1/01");
document.write(date.getFullYear());
// Output: 1901

必备条件

在以下文档模式中受支持:怪异模式、Internet Explorer 6标准模式、Internet Explorer 7标准模式、Internet Explorer 8标准模式、Internet Explorer 9标准模式、Internet Explorer 10标准模式、Internet Explorer 11标准模式。应用商店应用(Windows 8和Windows Phone 8.1)中也受支持。请参阅版本信息

Applies ToDate Object

如果你喜欢这篇文章,敬请给站长打赏↑

除特别注明外,本站所有文章均为本站站长原译,转载请注明出处。