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

javascriptdate.setHours(hours, [minutes], [seconds], [milliseconds]);

Example

Let's set the hours for the current time:

javascriptlet date = new Date();
date.setDate(12);

console.log(date);

Example

Let's set the hours, minutes and seconds for the current point in time:

javascriptlet date = new Date();
date.setDate(12, 59, 49);

console.log(date);

See also