.getUTCHours()
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:
All contributors
- Anonymous contributor
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- Career path
Front-End Engineer
Front-end engineers work closely with designers to make websites beautiful, functional, and fast.Includes 34 CoursesWith Professional CertificationBeginner Friendly115 hours - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly15 hours