JS Built-ins
← Date41 / 120
DategetHoursbeginner

getHours() β€” returns 12

πŸ“– 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()

Returns the hour (0–23) in local time.

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

πŸ’‘ Hints (1)
  • β€’ The 4th argument to the Date constructor is hours (0–23)