Add Hours to a Date Object using JavaScript

avatar

Borislav Hadzhiev

Last updated: Oct 25, 2021

banner

Photo from Unsplash

Add Hours to a Date Object using JavaScript #

Use the setHours() method to add hours to a date object. You can call the getHours() method to get the hour for the specified date and use the addition (+) operator to add as many hours as necessary to the date object.

index.js
// 👇️ current date const now = new Date(); now.setHours(now.getHours() + 1); // 👉️ add 1 Hour console.log(now); // 👇️ another date const date = new Date('September 24, 2025 07:24:00'); date.setHours(date.getHours() + 4); // 👉️ add 4 Hours console.log(date); // 👉️️ Wed Sep 24 2025 11:24:00

We used the Date.setHours method to set the hours for the date. The only parameter we passed to the method is a value for the hours.

Because we want to add hours to the date object, we used the Date.getHours to get the hour for the date and increased it.

Note that the date could roll over to the next day, e.g. if you add 2 hours and it's already 11 PM.

index.js
const date = new Date('September 24, 2025 23:24:00'); date.setHours(date.getHours() + 2); // 👉️ add 2 Hours console.log(date); // 👉️️ Wed Sep 25 2025 01:24:00

In the example, we added 2 hours to September 24th, 23:24 O'clock and the date rolled over to September 25th 01:24 O'clock.

The setHours method mutates the original date object, if you need to avoid this, you can create a copy of the date object and call the method on the copy.
index.js
const date = new Date('September 24, 2025 23:24:00'); const copy = new Date(date); copy.setHours(copy.getHours() + 2); // 👉️ add 2 Hours console.log(copy); // 👉️️ Wed Sep 25 2025 01:24:00 console.log(date); // 👉️ Wed Sep 24 2025 23:24:00

We created a copy of the date object, so we don't change it contents using the setHours method.

Further Reading #

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.