JavaScript getHours()Method
Example
Return the hour field of the time according to the local time:
var d = new Date();
var n = d.getHours();
var n = d.getHours();
nOutput:
Try it Yourself »
Definition and Usage
The getHours() method returns the hour field of the time.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the getHours() method.
Syntax
Date.getHours()
Return Value
| Type | Description |
|---|---|
| Number | The return value is an integer between 0 (midnight) and 23 (11 PM). |
Technical Details
| JavaScript Version: | 1.0 |
|---|
More Examples
Example
Return the hour field of the specified time:
var d = new Date("July 21, 1983 01:15:00");
var n = d.getHours();
var n = d.getHours();
nOutput:
1
Try it Yourself »
Display the current time
How to use getHours(), getMinutes(), and getSeconds() to display the current time.
Other Extensions
JavaScript Date Object