Deprecated
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 compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
El mètode setYear()
assigna l'any per a una data especificada, d'acord a l'hora local. Com que setYear()
no utilitza anys complerts ("el problema de l'any 2000"), aquest mètode està en desús i s'ha reemplaçat pel mètode setFullYear()
.
Sintaxi
objecteData.setYear(any)
Paràmetres
any
- Un nombre sencer.
Descripció
Si any
és un nombre entre 0 i 99 (inclòs), llavors s'assigna 1900 + any
a objecteData
. En cas contrari, s'assigna any
a objecteData
.
Exemples
Utilitzar setYear()
Les dues primeres línies assignen el valor 1996 a l'any. La tercera línia assigna el valor 2000 a l'any.
var elGranDia = new Date();
elGranDia.setYear(96);
elGranDia.setYear(1996);
elGranDia.setYear(2000);
Especificacions
Especificació | Estat | Comentaris |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Definició inicial. Implementat a JavaScript 1.0. |
ECMAScript 5.1 (ECMA-262) The definition of 'Date.prototype.getYear' in that specification. |
Standard | Definit a l'annex de compatibilitat (informatiu). |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Date.prototype.getYear' in that specification. |
Standard | Definit a l'annex de característiques adicionals per a navegadors web (normatiu). |
Compatibilitat amb navegadors
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suport bàsic | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Característica | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Suport bàsic | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |