A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date/getYear below:

Date.prototype.getYear() - JavaScript | MDN

Date.prototype.getYear()

已弃用: 不再推荐使用该特性。虽然一些浏览器仍然支持它,但也许已从相关的 web 标准中移除,也许正准备移除或出于兼容性而保留。请尽量不要使用该特性,并更新现有的代码;参见本页面底部的兼容性表格以指导你作出决定。请注意,该特性随时可能无法正常工作。

getYear() 方法返回指定的本地日期的年份。因为 getYear() 不返回千禧年("year 2000 problem"),所以这个方法不再被使用,现在替换为 getFullYear。

语法 返回值

getYear 方法返回一个年份减去 1900 的值;因此:

如果要同时考虑 2000 年之前和之后的年份,应该使用 getFullYear() 而不是 getYear(),以便指定完整年份。

向后兼容性 在 JavaScript 1.2 及更早版本中的行为

The getYear method returns either a 2-digit or 4-digit year:

示例 1900 年到 1999 年之间的年份

The second statement assigns the value 95 to the variable year.

var Xmas = new Date("December 25, 1995 23:15:00");
var year = Xmas.getYear(); // returns 95
年份大于 1999

The second statement assigns the value 100 to the variable year.

var Xmas = new Date("December 25, 2000 23:15:00");
var year = Xmas.getYear(); // returns 100
年份小于 1900

The second statement assigns the value -100 to the variable year.

var Xmas = new Date("December 25, 1800 23:15:00");
var year = Xmas.getYear(); // returns -100
设置和获取 1900 年到 1999 年之间的年份

The second statement assigns the value 95 to the variable year, representing the year 1995.

var Xmas.setYear(95);
var year = Xmas.getYear(); // returns 95
规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4