JavaScript Date setUTCHours()
Esempio
Impostare l'ora su 15, in base all'ora UTC:
const d = new Date();
d.setUTCHours(15);
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
Il metodo setUTCHours() imposta l'ora di un oggetto data, secondo UTC.
Può essere utilizzato anche per impostare minuti, secondi e millisecondi.
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
setUTCHours()
è 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.setUTCHours(hour, min, sec, millisec)
Valori dei parametri
Parameter | Description |
---|---|
hour | Required. An integer representing the hour.
Expected values are 0-23, but other values are allowed:
|
min | Optional. An integer representing the minutes.
Expected values are 0-59, but other values are allowed:
|
sec | Optional. An integer representing the seconds
Expected values are 0-59, but other values are allowed:
|
millisec | Optional. An integer representing the milliseconds
Expected values are 0-999, but other values are allowed:
|
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 l'ora alle 15:35:01 UTC
const d = new Date();
d.setUTCHours(15, 35, 1);
Esempio
Imposta l'ora su 48 ore fa , utilizzando i metodi UTC:
const d = new Date();
d.setUTCHours(d.getUTCHours() - 48);