Date.prototype.getHours()

The getHours() method returns the hour for the specified date, according to local time.

Syntax

dateObj.getHours()

Return value

An integer number, between 0 and 23, representing the hour for the given date according to local time.

Examples

Using getHours()

The second statement below assigns the value 23 to the variable hours, based on the value of the Date object Xmas95.

let Xmas95 = new Date('December 25, 1995 23:15:30');
let hours = Xmas95.getHours();

console.log(hours); // 23

Specifications

Specification Status Comment
ECMAScript Latest Draft (ECMA-262)
The definition of 'Date.prototype.getHours' in that specification.
Draft
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Date.prototype.getHours' in that specification.
Standard
ECMAScript 5.1 (ECMA-262)
The definition of 'Date.prototype.getHours' in that specification.
Standard
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.0.

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
getHoursChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support YesSafari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 1.0nodejs Full support Yes

Legend

Full support  
Full support

See also