The base date as a Date object or timestamp (number)
The hours as a number (0-23), or NaN if invalid
// Get hours from Date object
const result = getHours(new Date(2025, 0, 15, 14, 30));
// Returns: 14
// Get hours from timestamp
const result2 = getHours(1704110400000); // 2024-01-01 12:00:00
// Returns: 12
// Midnight (start of day)
const result3 = getHours(new Date(2024, 0, 1, 0, 0, 0));
// Returns: 0
// End of day
const result4 = getHours(new Date(2024, 0, 1, 23, 59, 59));
// Returns: 23
// Invalid date returns NaN
const result5 = getHours(new Date("invalid"));
// Returns: NaN
Get the hours of the given date.
This function validates arguments before processing and returns the hours (0-23) of the given date in 24-hour format. Returns NaN for invalid input.