JavaScript Date.prototype.getHours() Method
The getHours() method returns the hour of a date, from 0 to 23. Similar methods return the minutes, seconds and milliseconds.
Description
The getHours() method returns the hour, from 0 to 23, in local time. The related getMinutes(), getSeconds() and getMilliseconds() methods return the other parts of the time, and each has a getUTC...() version.
Getting the hour is a simple way to show a greeting that suits the time of day, or to check whether a shop is open. For formatted times, such as "2:05 pm", toLocaleTimeString() handles the 12- or 24-hour clock and leading zeros for you.
Like the other get...() methods without "UTC" in their name, it uses the time zone of the user's device, so the same moment can give different results for users in different places. Each has a getUTC...() counterpart for UTC, and for showing a date in a particular time zone, toLocaleString() with the timeZone option is the easiest approach.
Syntax
date.getHours()Return Value
The hour in local time, from 0 to 23.
Example
Browser Support
The following information will show you the current browser support for the Date.prototype.getHours() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





