getters
Date.prototype.getHours
Returns the hour of the date in LOCAL time as an integer from 0 to 23. Companion methods getMinutes, getSeconds, and getMilliseconds work the same way for their respective units.
date.getHours() Parameters
| Parameter | Purpose |
|---|---|
| () | no arguments; returns 0-23 |
| local time | use getUTCHours for UTC hour |
Examples
console.log(new Date('2026-07-19T15:30:00Z').getUTCHours()); // 15 24-hour clock
const d = new Date(); console.log(`${d.getHours()}:${String(d.getMinutes()).padStart(2,'0')}`); HH:mm local
console.log(new Date('2026-07-19T23:59:59Z').getUTCHours()); // 23 midnight is 0, not 24
Gotcha
Uses 24-hour clock (0-23). Local hour depends on the host timezone and DST, so the same instant returns different values on different machines.
Related
Date.prototype.getMinutes
Returns the minutes portion of the date in LOCAL time as an integer from 0 to 59. The identically shaped getSeconds (0-59) and getMilliseconds (0-999) round out the sub-hour getters.
Date.prototype.getFullYear
Returns the 4-digit year of the date according to LOCAL time. Prefer this over the deprecated getYear(), which returns year-1900.
Date.prototype.getMonth
Returns the month of the date in LOCAL time as an integer from 0 (January) to 11 (December). This zero-based indexing is the single most common source of off-by-one date bugs in JavaScript.
Date.prototype.getDate
Returns the day of the month (1-31) in LOCAL time. Do not confuse this with getDay, which returns the weekday.
Date.prototype.getDay
Returns the weekday of the date in LOCAL time as an integer from 0 (Sunday) to 6 (Saturday). Named confusingly close to getDate but returns something completely different.