Date.prototype.getFullYear()
Date 实例的 getFullYear() 方法根据当地时间返回该日期的年份。
¥The getFullYear() method of Date instances returns the year for this date according to local time.
使用此方法代替 getYear() 方法。
¥Use this method instead of the getYear() method.
Try it
语法
参数
返回值
描述
¥Description
与 getYear() 不同,getFullYear() 返回的值是绝对数字。对于 1000 年到 9999 年之间的日期,getFullYear() 返回一个四位数字,例如 1995。使用此功能可确保年份符合 2000 年之后的年份。
¥Unlike getYear(), the value returned by getFullYear() is an absolute number. For dates between the years 1000 and 9999, getFullYear() returns a four-digit number, for example, 1995. Use this function to make sure a year is compliant with years after 2000.
示例
使用 getFullYear()
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-date.prototype.getfullyear |
浏览器兼容性
BCD tables only load in the browser