.getUTCHours()
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
Looking to contribute?
- 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.