From http://www.w3schools.com (Copyright Refsnes Data)
JavaScript Date Object
The getHours() method returns the hour of a time.
| dateObject.getHours() |
Note: The value returned by getHours() is a two digit number. However, the return value is not always two digits, if the value is less than 10 it only returns one digit.
Note: This method is always used in conjunction with a Date object.
Example 1Get the hour of the current time:
The output of the code above will be: Try it yourself » |
Example 2Get the hour from a specific date and time:
The output of the code above will be:
Try it yourself » |
More Examples |
Display the current time
How to use getHours(), getMinutes(), and getSeconds() to display the current time.
JavaScript Date Object
From http://www.w3schools.com (Copyright Refsnes Data)