offline version v3


136 of 264 menu

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

enru