--- title: Date.prototype.getFullYear() slug: Web/JavaScript/Reference/Global_Objects/Date/getFullYear translation_of: Web/JavaScript/Reference/Global_Objects/Date/getFullYear ---
Il metodo getFullYear()
restituisce l'anno della data specificata in accordo con l'ora locale.
Utilizza questo metodo invece di quello {{jsxref("Date.prototype.getYear()", "getYear()")}}.
dateObj.getFullYear()
Un numero corrispondente all'anno della data fornita, in accordo con l'ora locale.
Il valore restituito da getFullYear()
è un numero assoluto. Per le date tra gli anni 1000 e 9999, getFullYear()
restituisce un numero a 4 cifre, per esempio, 1995. Usa quetsa funzione per essere sicuro che un anno sia compiacente con gli anni dopo il 2000.
getFullYear()
Il seguente esempio assegna il valore a quattro cifre dell'anno corrente alla variabile year
.
var today = new Date(); var year = today.getFullYear();
Specification | Status | Comment |
---|---|---|
{{SpecName('ES1')}} | {{Spec2('ES1')}} | Definizione iniziale. Implementata in JavaScript 1.3. |
{{SpecName('ES5.1', '#sec-15.9.5.10', 'Date.prototype.getFullYear')}} | {{Spec2('ES5.1')}} | |
{{SpecName('ES6', '#sec-date.prototype.getfullyear', 'Date.prototype.getFullYear')}} | {{Spec2('ES6')}} | |
{{SpecName('ESDraft', '#sec-date.prototype.getfullyear', 'Date.prototype.getFullYear')}} | {{Spec2('ESDraft')}} |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("javascript.builtins.Date.getFullYear")}}