Easy Tutorial
❮ Prop Style Columncount Jsref Throw ❯

JavaScript setHours() Method

JavaScript Date Object

Example

Set the time field to 15:

d Output result:


Definition and Usage

The setHours() method is used to set the hour field for a specified time.

This method can also be used to set the minutes, seconds, and milliseconds.


Browser Support

All major browsers support the setHours() method.


Syntax

Parameter Values

Parameter Description
hour Required. A number representing the hour, between 0 (midnight) and 23 (11 PM), in local time. -1 is the last hour of the previous day. <br> 24 is the first hour of the next day.
min Optional. A number representing the minutes, between 0 and 59. Before EMCAScript standardization, this parameter was not supported: -1 is the last minute of the previous hour. <br> 60 is the first minute of the next hour.
sec Optional. A number representing the seconds, between 0 and 59. Before EMCAScript standardization, this parameter was not supported: -1 is the last second of the previous minute. <br> 60 is the first second of the next minute.
millisec Optional. A number representing the milliseconds, between 0 and 999. Before EMCAScript standardization, this parameter was not supported: -1 is the last millisecond of the previous second. <br> 1000 is the first millisecond of the next second.

Return Value

Type Description
Number The number of milliseconds between the date object and midnight January 1, 1970.

Technical Details

| JavaScript Version: | 1.0 | | --- | --- |


More Examples

Example

In this example, we will set the time to 15:35:01 using the setHours() method:

d Output result:

Example

Set the time to 48 hours ago:

d Output result:


JavaScript Date Object

❮ Prop Style Columncount Jsref Throw ❯