JavaScript Date getUTCHours()
Examples
Get the UTC hours:
const d = new Date();
let hour = d.getUTCHours();
Try it Yourself »
Get the UTC hours from a specific date:
const d = new Date("July 21, 1983 01:15:00");
let hour = d.getUTCHours();
Try it Yourself »
More examples below.
Definition and Usage
getUTCHours()
returns the hour (0 to 23) of a date.
getUTCHours()
returns the hour according to UTC.
Notes
UTC (Universal Time Coordinated) is the time set by the World Time Standard.
UTC time is the same as GMT time (Greenwich Mean Time).
All JavaScript getUTC methods assume that the date is of local time.
Syntax
Date.getUTCHours()
Parameters
NONE |
Return Value
A number. The hour of a date (0 to 23). |
Browser Support
getUTCHours()
is an ECMAScript1 (ES1) feature.
ES1 (JavaScript 1997) is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
More Examples
Use all getUTC methods to display the universal time:
function addZero(i) {
if (i < 10) {i = "0" + i}
return i;
}
const d = new Date();
let h = addZero(d.getUTCHours());
let m = addZero(d.getUTCMinutes());
let s = addZero(d.getUTCSeconds());
let time = h + ":" + m + ":" + s;
Try it Yourself »