Favorites

JavaScript Date.prototype.getHours() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Date.prototype.getHours()
JavaScript Date Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

const d = new Date();
const h = d.getHours();
console.log(h, d.getMinutes(), d.getSeconds());
console.log(h < 12 ? 'Good morning' : h < 18 ? 'Good afternoon' : 'Good evening');

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee