Home  >  Article  >  Web Front-end  >  JavaScript method setUTCHours() to set hours (0 - 23) according to Universal Time (UTC)

JavaScript method setUTCHours() to set hours (0 - 23) according to Universal Time (UTC)

黄舟
黄舟Original
2017-11-08 09:54:531639browse

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)
secmillisec
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.

Note

If the min, sec and millisec parameters are not specified, the values ​​returned from the getUTCMinutes, getUTCSeconds and getUTCMilliseconds methods are used.

If the parameters you specify are outside the specified range, setUTCHours attempts to update the date information in the Date

object accordingly. For example, if the value of the sec parameter is 100, then 1 minute (min + 1) is added, and the number of seconds is 40.

Return value

Adjusted date expressed in milliseconds.

Tips and

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.

Example

Example 1

In 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 2

In 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn