Home > Article > Web Front-end > JavaScript method setUTCHours() to set hours (0 - 23) according to Universal Time (UTC)
Definition and Usage
The setUTCHours() method is used to set the hours (0 - 23) based on Universal Time (UTC).
Syntax
dateObject.setUTCHours(hour,min,sec,millisec)
Parameters | Description |
hour | Required. The value of the hour field to set for the dateObject. This parameter is an integer between 0 ~ 23. |
min | ##Optional. The value of the minutes field to set for the dateObject. This parameter is an integer between 0 ~ 59. |
Optional. The value of the seconds field to set for the dateObject. This parameter is an integer between 0 ~ 59. | |
Optional. The value of the milliseconds field to set for the dateObject. This parameter is an integer between 1 ~ 999. |
Notes:
Note: This method is always used in conjunction with a Date object. Tip: For more information about Universal Coordinated Time (UTC), please refer to Baidu Encyclopedia. ExampleExample 1In this example, we will set the UTC hours to 23 through the setUTCHours() method:<script type="text/javascript"> var d = new Date();d.setUTCHours(23);document.write(d); </script>Output: Example 2In this example, we will set the UTC hour to 23:15:06 through the setUTCHours() method:
<script type="text/javascript"> var d = new Date();d.setUTCHours(23,15,6);document.write(d); </script>Output:
Thu Nov 09 2017 07:15:06 GMT+0800 (中国标准时间)
The above is the detailed content of JavaScript method setUTCHours() to set hours (0 - 23) according to Universal Time (UTC). For more information, please follow other related articles on the PHP Chinese website!