JavaScript setUTCHours() Method
Example
Set the hours field to 15 according to Universal Time (UTC):
var d = new Date();
d.setUTCHours(15);
d Output according to local time:
Try it »
Definition and Usage
The setUTCHours() method is used to set the hours (0 - 23) according to Universal Time (UTC).
This method can be used to set the minutes, seconds, and milliseconds.
**Tip:** Coordinated Universal Time, also known as Universal Time, World Standard Time, or International Coordinated Time, abbreviated as UTC (Universal Coordinated Time).
**Note:** UTC time is the same as GMT (Greenwich) time.
Browser support





All major browsers support the setUTCHours() method.
Syntax
Date
.setUTCHours(
hour
,
min
,
sec
,
millisec
)
Parameter Values
| Parameters | Description |
|---|---|
| hour | Required. The value to set for the hours field of dateObject.
This parameter is an integer between 0 and 23: |
This parameter is an integer between 0 and 59:
- -1 is the last minute of the previous hour.
- 60 is the first minute of the next hour
This parameter is an integer between 0 and 59:
- -1 is the last second of the previous minute.
- 60 is the first second of the next minute.
This parameter is an integer between 1 and 999:
- -1 is the last millisecond of the previous second.
- 1000 is the first millisecond of the next second.
Return Value
| Type | Description |
|---|---|
| Number | The number of milliseconds from January 1, 1970 to the adjusted date. |
Technical Details
| JavaScript version: | 1.3 |
|---|
More examples
Example
Set the time to 15:35:01 according to Universal Time (UTC):
var d = new Date();
d.setUTCHours(15,35,1);
d Output the result according to local time:
Try it »
Example
Set the time to 48 hours earlier according to Universal Time (UTC):
var d = new Date();
d.setUTCHours(d.getUTCHours()-48);
d Output the result according to local time:
Try it »
JavaScript Date object