Date.getUTCHours()

Returns the hour, according to universal time (from 0-23)

The getUTCHours() method returns the hours in the specified date according to universal time.

var date1 = new Date('December 31, 1975, 23:15:30 GMT+11:00');
var date2 = new Date('December 31, 1975, 23:15:30 GMT-11:00');

console.log(date1.getUTCHours());
// expected output: 12

console.log(date2.getUTCHours());
// expected output: 10

Syntax

dateObj.getUTCHours()

Return value

An integer number, between 0 and 23, representing the hours in the given date according to universal time.

Examples

Using getUTCHours()

The following example assigns the hours portion of the current time to the variable hours.

var today = new Date();
var hours = today.getUTCHours();

References

Contributors to this page

Uros Durdevic

Last updated