JS Built-ins
← Date45 / 120
DategetHoursintermediate

getHours() β€” comparison of two dates

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

You can compare hours of two dates to determine which is earlier in the day.

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

πŸ’‘ Hints (1)
  • β€’ getHours() values can be compared directly since they are plain numbers