JavaScript getHours() Method
Example
Return the hours field of a time based on local time:
var d = new Date();
var n = d.getHours();
n Output result:
Try it »
Definition and Usage
The getHours() method returns the hours field of a 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 hours field of a specified time:
var d = new Date("July 21, 1983 01:15:00");
var n = d.getHours();
n Output result:
1
Try it »
Display the current time
How to use getHours(), getMinutes(), and getSeconds() to display the current time.
JavaScript Date object