Home > Web Front-end > JS Tutorial > body text

The JavaScript method getUTCHours() returns time hours based on Universal Time (UTC)

黄舟
Release: 2017-11-06 14:25:46
Original
1640 people have browsed it

Definition and Usage

The getUTCHours() method returns the hours of time based on Universal Time (UTC).

Syntax

dateObject.getUTCHours()
Copy after login

Return value

Return dateObject hour field expressed in universal time, the value is between 0 (midnight) ~ 23 (11 pm) The integer.

Tips and Notes:

Note: The value returned by getUTCHours() is a two-digit number. However, the return value is not always two digits, if the value is less than 10, only one digit is returned.

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 get the UTC hour of the current time:

<script type="text/javascript">

var d = new Date()
document.write(d.getUTCHours())

</script>
Copy after login

Output:

6
Copy after login

Example 2

Here, we will extract UTC hours from a specific date and time:

<script type="text/javascript">

var born = new Date("July 21, 1983 01:15:00")
document.write(born.getUTCHours())

</script>
Copy after login

Output:

17
Copy after login

According to universal time, javascript Date.getUTCHours( ) method returns the time on the specified date. The value returned by getUTCHours is an integer between 0 and 23.

Example:

The following example prints the time part of the current time variable hrs.

<html>
<head>
<title>JavaScript getUTCHours Method</title>
</head>
<body>
<script type="text/javascript">
  var dt = new Date();
  document.write("getUTCHours() : " + dt.getUTCHours() ); 
</script>
</body>
</html>
Copy after login

This will produce the following results for India time zone:

getUTCHours() : 14
Copy after login


The above is the detailed content of The JavaScript method getUTCHours() returns time hours based on Universal Time (UTC). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template