The getHours method returns the hour of the point in time stored in a Date object. The value returned by this method is an integer number from 0 to 23.
Syntax
myDate.getHours()
With myDate being an object based on the Date object.
Instead of being instantiated from a class, in JavaScript objects are created by replicating other objects. This paradigm is called Prototype-based programming.
Example
The following code uses the getHours method to return the current hour:
<script type="text/javascript">
var currentDate = new Date();
var currentHour = currentDate.getHours();
document.write("The current hour is: " + currentHour + ".");
</script>
var currentDate = new Date();
var currentHour = currentDate.getHours();
document.write("The current hour is: " + currentHour + ".");
</script>
Technical Details
The getHours method belongs to the Date object, it is available since the version 1.0 of JavaScript, and it is supported in all major browsers.
JavaScript Manual >> Date Object >> getHours Method