Date.getHours()
Returns the hour (from 0-23)
The getHours() method returns the hour for the specified date, according to local time.
var birthday = new Date('March 13, 08 04:20');
console.log(birthday.getHours());
// expected output: 4
Syntax
dateObj.getHours()
Return value
An integer number, between 0 and 23, representing the hour for the given date according to local time.
Description
The value returned by getFullYear()
is an absolute number. For dates between the years 1000 and 9999, getFullYear()
returns a four-digit number, for example, 1995. Use this function to make sure a year is compliant with years after 2000.
Examples
Using getHours()
getHours()
The second statement below assigns the value 23 to the variable hours
, based on the value of the Date
object Xmas95
.
var Xmas95 = new Date('December 25, 1995 23:15:30');
var hours = Xmas95.getHours();
console.log(hours); // 23
References
Contributors to this page
Uros Durdevic
Last updated