--- title: Date.prototype.getFullYear() slug: Web/JavaScript/Reference/Global_Objects/Date/getFullYear translation_of: Web/JavaScript/Reference/Global_Objects/Date/getFullYear ---
{{JSRef}}

 

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()")}}.

{{EmbedInteractiveExample("pages/js/date-getfullyear.html")}}

Sintassi

dateObj.getFullYear()

Valore di ritorno

Un numero corrispondente all'anno della data fornita, in accordo con l'ora locale.

Descrizione

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.

Esempi

Utilizzando getFullYear()

Il seguente esempio assegna il valore a quattro cifre dell'anno corrente alla variabile year.

var today = new Date();
var year = today.getFullYear();

Specificazioni

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')}}  

Compatibilità Browser

{{Compat("javascript.builtins.Date.getFullYear")}}

Vedere anche