JavaScript Data impostataAnno Completo ()
Esempio 1
const d = new Date();
d.setFullYear(2020);
Definizione e utilizzo
setFullYear()
imposta l'anno di una data.
setFullYear()
può anche impostare mese e giorno.
Esempio 2
const d = new Date();
d.setFullYear(2020, 10, 3);
Esempio 3
Imposta la data a sei mesi fa :
const d = new Date();
d.setFullYear(d.getFullYear(), d.getMonth() - 6);
Supporto browser
setFullYear()
è una funzione ECMAScript1 (ES1).
ES1 (JavaScript 1997) è completamente supportato in tutti i browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Sintassi
Date.setFullYear(year, month, day)
Parametri
year | Required. The year. Negative values are allowed. |
month | Optional. The month (0 to 11). Higher and lower values are handeled with date maths:
|
day | Optional. The day (0 to 31). Higher and lower values are handeled with date maths:
|
Valore di ritorno
Un numero. Numero di millisecondi tra la data e il 1 gennaio 1970 00:00:00 UTC. |