Data JavaScript.UTC()
Przykład
Uzyskaj liczbę milisekund między datą a 1 stycznia 1970 r.:
let ms = Date.UTC(2020, 02, 30);
Więcej przykładów „Wypróbuj sam” poniżej.
Definicja i użycie
Metoda Date.UTC() zwraca liczbę milisekund między określoną datą a północą 1 stycznia 1970 r. zgodnie z UTC.
Uwagi
UTC (Universal Time Coordinated) to czas ustawiony przez Światowy Standard Czasu.
Czas UTC jest taki sam jak czas GMT (Greenwich Mean Time).
Obsługa przeglądarki
Date.UTC()
to funkcja ECMAScript1 (ES1).
ES1 (JavaScript 1997) jest w pełni obsługiwany we wszystkich przeglądarkach:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Składnia
Date.UTC(year, month, day, hours, minutes, seconds, millisec)
Date.UTC() jest statyczną metodą obiektu Date.
Nie możesz go używać w dniu takim jak d.UTC()
Składnia to zawsze Date.UTC().
Wartości parametrów
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:
|
Szczegóły techniczne
Wartość zwrotu: | Liczba reprezentująca liczbę milisekund między określoną datą i godziną a północą 1 stycznia 1970 |
---|---|
Wersja JavaScript: | ECMAScript 1 |
Więcej przykładów
Przykład
Utwórz obiekt daty, używając czasu UTC zamiast czasu lokalnego:
let d = new Date(Date.UTC(2020, 02, 30));