Date.getHours()
JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE 3+, Opera3+ Syntax
date.getHours()
Description
The getHours() method returns the hour portion of the date expressed as an integer from 0 (12:00 a.m. midnight) to 23 (11:00 p.m.).
Example
The code in Listing 6.74 displays the current hour as an integer from 0 to 23 using the getHours() method.
Listing 6.74 Using the getHours() Method to Return the Current Hour
<html> <script language="JavaScript"> <!-- Hide //Create a Date object that contains the current date and time. theDate = new Date(); //Display the hour document.write("The hour is ",theDate.getHours()); //Hide End --> </script> </html> |
Get Pure JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.