To get the time of day in JavaScript or Node.js, we use the date’s getHour
method.
For instance, we write
const date = new Date();
const currentHour = date.getHours();
to create a date object with the current date and time with the Date
constructor.
And then we call getHours
on it to get the current hour of the day.