The JavaScript getUTCHours function returns the total number of hours ranging between 0 and 23 on a given date according to Universal Coordinated Time (UTC).
The syntax of the getUTCHours function is:
Date.getUTCHours()
Return Value: The getUTCHours() method returns an integer value from 0 to 23 representing the Hours according to UTC.
JavaScript getUTCHours example
I am using the getUTCHours to return the total number of hours as per the universal time from the current date and time.
const dt = new Date();
let h = dt.getUTCHours();
console.log(h);
console.log(dt);
7
Fri Jun 12 2026 19:04:29 GMT-1200 (GMT-12:00)
Example 2: Using getUTCHours on a String date
In this JavaScript example, we use the Date() constructor to parse a string date to a datetime. Next, we apply the getUTCHours function to display the universal time hours from the custom date.
If you observe the result, it returns 22 Hours instead of 10 Hours as the output. As there is a 12 Hours time difference between UTC and the system time, it adds that number and returns the output.
Total = Actual (10) + UTC Difference (12) = 22
const dt = new Date("April 2, 2017 10:11:22");
let h = dt.getUTCHours();
console.log(h);
console.log(dt);
22
Sun Apr 02 2017 10:11:22 GMT-1200 (GMT-12:00)
Example 3: If we use the JavaScript getUTCHours() function on a date without a time. It considers 00:00:00 as the default time, and the hours value is 0. As it adds the time difference of 12 hours, the result is 12.
const dt = new Date("April 2, 2017");
let h = dt.getUTCHours();
console.log(h);
console.log(dt);
12
Sun Apr 02 2017 00:00:00 GMT-1200 (GMT-12:00)
Example 4: If we use the getUTCHours() function on an invalid date, it returns NaN.
const dt = new Date("April 40, 2025 10:10:10");
console.log(dt.getUTCHours());
console.log(dt);
NaN
Invalid Date
What is the difference between getHours() and getUTCHours() in JavaScript?
Both getHours() and getUTCHours() methods return the hours values from the given date.
- getHours(): It returns the hours value from the given date according to the local system time zone.
- getUTCHours(): It returns the hours value from the given date according to the Universal Coordinated Time (UTC) zone.
As we set the system time zone to 12 hours before UTC, there is a difference in the getHours() and getUTCHours() methods. Here, the getHours() returns 5 hours from the given date. However, the getUTCHours() returns 17 (12 Hours difference + 5 Hours from the date).
const dt = new Date("2026-01-01 05:10:11");
console.log(dt.getUTCHours());
console.log(dt.getHours());
console.log(dt);
17
5
Thu Jan 01 2026 05:10:11 GMT-1200 (GMT-12:00)