Date.getHours() (Method)

Returns the hour value for a date/time.

Availability:

ECMAScript edition - 2
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.02
Netscape - 2.0
Netscape Enterprise Server - 2.0
Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-myDate.getHours()

The hours of the time value contained in the receiving object. This is returned as an integer in the range 0 to 23 inclusive.

The value is computed according to local time coordinates.

Example code:

   <HTML>

   <HEAD></HEAD>

   <BODY>

   <SCRIPT>

   // Generate a flag based on work or play time

   myDate = new Date();

   myHours = myDate.getHours();

   if((myHours > 8) && (myHours < 17))

   {

   document.write("At work");

   }

   else

   {

   document.write("At play");

   }

   </SCRIPT>

   </BODY>

   </HTML>

See also:Date.prototype, Date.setHours(), Date.setUTCHours()

Cross-references:

ECMA 262 edition 2 - section - 15.9.5.14

ECMA 262 edition 3 - section - 15.9.5.18