JavaScript Date setUTCMuse()
Esempio
Imposta il mese su 4 (maggio):
const d = new Date();
d.setUTCMonth(4);
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
Il metodo setUTCMonth() imposta il mese (da 0 a 11) di un oggetto data, secondo UTC.
Nota: gennaio è 0, febbraio è 1 e così via.
Appunti
UTC (Universal Time Coordinated) è l'ora impostata dal World Time Standard.
L'ora UTC è la stessa dell'ora GMT (Greenwich Mean Time).
Supporto browser
setUTCMonth()
è 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.setUTCMonth(month, day)
Valori dei parametri
Parameter | Description |
---|---|
month | Required. An integer representing the month
Expected values are 0-11, but other values are allowed:
|
day | Optional. An integer representing the day of month
Expected values are 1-31, but other values are allowed:
If the month has 31 days:
If the month has 30 days:
|
Dettagli tecnici
Valore di ritorno: | Un numero, che rappresenta il numero di millisecondi tra l'oggetto data e la mezzanotte del 1 gennaio 1970 |
---|---|
Versione JavaScript: | ECMAScript 1 |
Altri esempi
Esempio
Impostare il mese su 4 (maggio) e il giorno su 20:
const d = new Date();
d.setUTCMonth(4, 20);
Esempio
Imposta come data l'ultimo giorno del mese scorso:
const d = new Date();
d.setUTCMonth(d.getUTCMonth(), 0);