JavaScript Date.UTC()
Esempio
Ottieni il numero di millisecondi tra una data e il 1 gennaio 1970:
let ms = Date.UTC(2020, 02, 30);
Altri esempi "Provalo da solo" di seguito.
Definizione e utilizzo
Il metodo Date.UTC() restituisce il numero di millisecondi tra una data specificata e la mezzanotte del 1 gennaio 1970, secondo UTC.
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
Date.UTC()
è 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.UTC(year, month, day, hours, minutes, seconds, millisec)
Date.UTC() è un metodo statico dell'oggetto Date.
Non puoi usarlo in una data come d.UTC()
La sintassi è sempre Date.UTC().
Valori dei parametri
Parameter | Description |
---|---|
year | Required. A four-digit value representing the year, negative values are allowed |
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:
|
hour | Optional. Default 0. An integer representing the hour.
Expected values are 0-23, but other values are allowed:
|
min | Optional. Default 0. An integer representing the minutes.
Expected values are 0-59, but other values are allowed:
|
sec | Optional. Default 0. An integer representing the seconds
Expected values are 0-59, but other values are allowed:
|
millisec | Optional. Default 0. 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 la data e l'ora specificata e la mezzanotte del 1 gennaio 1970 |
---|---|
Versione JavaScript: | ECMAScript 1 |
Altri esempi
Esempio
Crea un oggetto data utilizzando l'ora UTC anziché l'ora locale:
let d = new Date(Date.UTC(2020, 02, 30));