setHours method
The setHours method allows you
to change the hour value of the
date object.
It takes hour as first parameter. It
can also take minutes, seconds and
milliseconds.
Syntax
date.setHours(hours, [minutes], [seconds], [milliseconds]);
Example
Let's set the hours for the current time:
let date = new Date();
date.setDate(12);
console.log(date);
Example
Let's set the hours, minutes and seconds for the current point in time:
let date = new Date();
date.setDate(12, 59, 49);
console.log(date);
See also
-
the
setFullYearmethod
that sets the year -
the
setMonthmethod
that sets the month -
the
setDatemethod
that sets the day of the month -
the
setMinutesmethod
that sets the minutes -
the
setSecondsmethod
that sets the seconds -
the
setMillisecondsmethod
that sets the milliseconds