How to Add Hours to a Date Object in JavaScript

avatar

Borislav Hadzhiev

Mon Oct 25 20212 min read

Add Hours to a Date Object in 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 #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee