.getUTCHours()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Jun 17, 2023Updated Jan 18, 2024
Contribute to Docs

The .getUTCHours() returns the hours for the provided date according to universal time.

Syntax

myDate.getUTCHours()

The .getUTCHours() method returns hours as an integer between 0-23 (midnight will return 0) for the provided date myDate.

Example

In the example below, the variable myDate stores the hours returned from a new Date object and logs the value to the console.

const myDate = new Date('1 January 2023 11:20 GMT+900');
console.log(myDate.getUTCHours());

Returns the following to the console:

2

Codebyte Example

In the following example, variables estDate and pstDate are defined to store a new Date object in Eastern Time and Pacific Time respectively. The method .getUTCHours() is then used to print the hours of the dates according to universal time. Run the example in the Codebyte below to test the results:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn JavaScript on Codecademy