JavaScript Data setUTCHours()
Przykład
Ustaw godzinę na 15, zgodnie z czasem UTC:
const d = new Date();
d.setUTCHours(15);
Więcej przykładów „Wypróbuj sam” poniżej.
Definicja i użycie
Metoda setUTCHours() ustawia godzinę obiektu daty zgodnie z UTC.
Może być również używany do ustawiania minut, sekund i milisekund.
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
setUTCHours()
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.setUTCHours(hour, min, sec, millisec)
Wartości parametrów
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:
|
Szczegóły techniczne
Wartość zwrotu: | Liczba reprezentująca liczbę milisekund między obiektem daty a północą 1 stycznia 1970 |
---|---|
Wersja JavaScript: | ECMAScript 1 |
Więcej przykładów
Przykład
Ustaw czas na 15:35:01 czasu UTC
const d = new Date();
d.setUTCHours(15, 35, 1);
Przykład
Ustaw czas na 48 godzin temu , używając metod UTC:
const d = new Date();
d.setUTCHours(d.getUTCHours() - 48);