English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript getHours() method

 JavaScript Date Object

getHours()Returns the hour of the specified date object based on local time (0-23).

getHours()The returned value is from 0 to23integer between.

Syntax:

date.getHours()
var d = new Date();
d.getHours();
Test and see‹/›

Browser compatibility

All browsers fully support the getHours() method:

Method
getHours()isisisisis

Technical Details

Return Value:0 to23are integers representing hours between
JavaScript Version:ECMAScript 1

More Examples

Return the hour of a specific date and time:

var d = new Date(#39;August 20, 1999 23:15:30');
d.getHours();
Test and see‹/›

Use the getHours(), getMinutes(), and getSeconds() methods to display the time:

setInterval(function () {
   var date = new Date();
   var x = document.getElementById('result');
   x.innerHTML = date.getHours() + " + date.getMinutes() + " + date.getSeconds();
}, 1000);
Test and see‹/›

 JavaScript Date Object