JavaScript Data setGodziny()
Przykład 1
const d = new Date();
d.setHours(15);
Definicja i użycie
setHours()
ustawia godzinę daty.
setHours()
można również ustawić minuty, sekundy i milisekundy.
Przykład 2
Ustaw godzinę na 15:35:01
const d = new Date();
d.setHours(15, 35, 1);
Przykład 3
Ustaw czas na 48 godzin temu :
const d = new Date();
d.setHours(d.getHours() - 48);
Obsługa przeglądarki
setHours()
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.setHours(hour, min, sec, millisec)
Parametry
hour | Required. The Hours.
0 to 23, but other values are allowed:
|
min | Optional. The Minutes.
0 to 59, but other values are allowed:
|
sec | Optional. The seconds.
0 to 59, but other values are allowed:
|
millisec | Optional. The milliseconds.
0 to 999, but other values are allowed:
|
Wartość zwrotu
Numer. Liczba milisekund między datą a 1 stycznia 1970 00:00:00 UTC. |