JavaScript Date getUTCHours() method - JavaScript Tutorial

JavaScript Date getUTCHours() method

BLUF: This tutorial on JavaScript Date getUTCHours() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Date getUTCHours() method

Understanding JavaScript Date getUTCHours() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The getUTCHours method in JavaScript retrieves the hour component of the given date in accordance with Coordinated Universal Time (UTC).

Syntax

The method getUTCHours is denoted by the syntax below:

Example

dateObj.getUTCHours()

Return

An integer ranging from 0 to 23 that signifies the hour of the day.

JavaScript Date getUTCHours method example

In this section, we will explore the getUTCHours method by examining several examples.

Example 1

Let’s examine an example that displays the current hour based on Coordinated Universal Time (UTC).

Example

<script>

var hour=new Date();

document.writeln("Hour value : "+hour.getUTCHours());

</script>

Output:

Output

Hour value : 12

Example 2

Let’s examine an example that demonstrates how to extract and display the hour from a specified date in accordance with Coordinated Universal Time (UTC).

Example

<script>

var hour1=new Date("August 15 1975 22:15:30 GMT+11:00");

var hour2=new Date("August 15 1975 22:15:30 GMT-11:00");

document.writeln("Hour value1 : "+hour1.getUTCHours()+"<br>");

document.writeln("Hour value2 : "+hour2.getUTCHours());

</script>

Output:

Output

Hour value1 : 11

Hour value2 : 9

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience