|
| JAVASCRIPT getHours() METHOD
The getHours() method in javascript returns the hour of time as numbers from 0 to 23.
The general format is:
dateObject.getHours();
If you want to return the hour with getHours() method, you will first have to create a new date object and then use the new date object with the getHours() method.
Example 1: Using getHours() for the hour as of current time
<script type="text/javascript">
var hh=new Date(); // creates a new date object
hh=hh.getHours(); // returns the hour
document.write(hh); // outputs the hour
</script>
The above will output:
Example 2: Using getHours() to get the hour of a specified date/time:
<script type="text/javascript">
var hh=new Date("January 16, 2008 21:37:23"); // creates a new date object
hh=hh.getHours(); // returns the hour
document.write(hh); // outputs the hour
</script>
The above will output:
See Also:
|
|