Пример 1
const d = new Date();
d.setHours(15);
Попробуйте сами »
Описание
setHours() sets the hour of a date.
setHours() can also set minutes, seconds and milliseconds.
Пример 3
Set the time to 48 hours ago:
const d = new Date();
d.setHours(d.getHours() - 48);
Попробуйте сами »
Поддержка браузера
setHours() — это функция ECMAScript1 (ES1).
ES1 (JavaScript 1997) полностью поддерживается во всех браузерах:
| Chrome | Edge | Firefox | Safari | Opera | IE |
| Да | Да | Да | Да | Да | Да |
Синтаксис
Date.setHours(hour, min, sec, millisec)
Параметры
| 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:
|
Возвращаемое значение
| Number. Number of milliseconds between the date and January 1, 1970 00:00:00 UTC. |