弃用
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the
兼容性表格
at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
getYear()
method returns the year in the specified date according to local time. Because
getYear()
does not return full years ("year 2000 problem"), it is no longer used and has been replaced by the
getFullYear()
方法。
dateObj.getYear()
A number representing the year of the given date, according to local time, minus 1900.
getYear()
is 100 or greater. For example, if the year is 2026,
getYear()
returns 126.
getYear()
is between 0 and 99. For example, if the year is 1976,
getYear()
returns 76.
getYear()
is less than 0. For example, if the year is 1800,
getYear()
returns -100.
To take into account years before and after 2000, you should use
getFullYear()
而不是
getYear()
so that the year is specified in full.
getYear()
method returns either a 2-digit or 4-digit year:
getYear()
is the year minus 1900. For example, if the year is 1976, the value returned is 76.
getYear()
is the four-digit year. For example, if the year is 1856, the value returned is 1856. If the year is 2026, the value returned is 2026.
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
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
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
The third statement assigns the value 95 to the variable
year
, representing the year 1995.
var Xmas = new Date('December 25, 2015 23:15:00');
Xmas.setYear(95);
var year = Xmas.getYear(); // returns 95
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Date.prototype.getYear' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getYear
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持
弃用。不要用于新网站。
Date
Date.UTC()
Date.now()
Date.parse()
Date.prototype.getDate()
Date.prototype.getDay()
Date.prototype.getFullYear()
Date.prototype.getHours()
Date.prototype.getMilliseconds()
Date.prototype.getMinutes()
Date.prototype.getMonth()
Date.prototype.getSeconds()
Date.prototype.getTime()
Date.prototype.getTimezoneOffset()
Date.prototype.getUTCDate()
Date.prototype.getUTCDay()
Date.prototype.getUTCFullYear()
Date.prototype.getUTCHours()
Date.prototype.getUTCMilliseconds()
Date.prototype.getUTCMinutes()
Date.prototype.getUTCMonth()
Date.prototype.getUTCSeconds()
Date.prototype.getYear()
Date.prototype.setDate()
Date.prototype.setFullYear()
Date.prototype.setHours()
Date.prototype.setMilliseconds()
Date.prototype.setMinutes()
Date.prototype.setMonth()
Date.prototype.setSeconds()
Date.prototype.setTime()
Date.prototype.setUTCDate()
Date.prototype.setUTCFullYear()
Date.prototype.setUTCHours()
Date.prototype.setUTCMilliseconds()
Date.prototype.setUTCMinutes()
Date.prototype.setUTCMonth()
Date.prototype.setUTCSeconds()
Date.prototype.setYear()
Date.prototype.toDateString()
Date.prototype.toGMTString()
Date.prototype.toISOString()
Date.prototype.toJSON()
Date.prototype.toLocaleDateString()
Date.prototype.toLocaleString()
Date.prototype.toLocaleTimeString()
Date.prototype.toSource()
Date.prototype.toString()
Date.prototype.toTimeString()
Date.prototype.toUTCString()
Date.prototype.valueOf()
Date.prototype[@@toPrimitive]
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()