Categories
JavaScript Answers

How to get the time of day in JavaScript or Node.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *