JavaScript setUTCHours()Method
Example
Set the hour field to 15 according to UTC:
d.setUTCHours(15);
dOutput according to local time:
Try it Yourself »
Definition and Usage
The setUTCHours() method is used to set the hour (0 - 23) according to UTC.
This method can also be used to set minutes, seconds, and milliseconds.
Tip:Coordinated Universal Time, also known as Universal Time Coordinated, World Standard Time, 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
Parameter Values
| Parameter | Description |
|---|---|
| hour | Required. The value of the hour field to be set for the dateObject. This parameter is an integer between 0 and 23:
|
| min | Optional. The value of the minute field to be set for the dateObject. This parameter is an integer between 0 and 59:
|
| sec | Optional. The value of the second field to be set for the dateObject. This parameter is an integer between 0 and 59:
|
| millisec | Optional. The value of the millisecond field to be set for the dateObject. This parameter is an integer between 1 and 999:
|
Return Value
| Type | Description |
|---|---|
| Number | The number of milliseconds between January 1, 1970 and the adjusted date. |
Technical Details
| JavaScript Version: | 1.3 |
|---|
More Examples
Example
Set the time to 15:35:01 according to UTC:
d.setUTCHours(15,35,1);
dOutput the result according to local time:
Try it Yourself »
Example
Set the time to 48 hours ago according to UTC:
d.setUTCHours(d.getUTCHours()-48);
dOutput the result according to local time:
Try it Yourself »
Other Extensions
JavaScript Date Object