JS Built-ins
← Date42 / 120
DategetHoursbeginner

getHours() β€” midnight is 0

πŸ“– Usage Example
const d = new Date(2024, 0, 15, 14, 30)
d.getHours()  // β†’ 14
// returns 0–23

Use getHours() to retrieve the hour (0–23) of a Date object in local time.

Date.prototype.getHours()

Midnight (the start of a day) has hours = 0.

Challenge: Verify that new Date(2024, 0, 15, 0).getHours() returns 0.

πŸ’‘ Hints (1)
  • β€’ Hour 0 is midnight (the very start of the day)