Categories
JavaScript Answers

How to Add 1 day to the Current Date with JavaScript?

Spread the love

To add 1 day to the current date with JavaScript, we can use the setDate method.

For instance, we can write:

const date = new Date();
date.setDate(date.getDate() + 1);
console.log(date)

to get the current day with getDate , then add 1 to it.

And then we pass that as the argument of setDate to add 1 to the current date .

We can also add 1 day to the current by adding 1 day in milliseconds.

For instance, we can write:

const date = new Date(Date.now() + (3600 * 1000 * 24))
console.log(date)

to get the current date and time in milliseconds with Date.now .

Then we add 3600 * 1000 * 24 milliseconds, which is the same as 1 day to it.

And we pass that to the Date constructor to get the date 1 day after the current date.

By John Au-Yeung

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

2 replies on “How to Add 1 day to the Current Date with JavaScript?”

@Atul, yes setDate is working well for the 28th of Feb. If you call setDate(29) on a Date object that is in February (in a non leap year) it will move the Date to first of March.
And in fact using setDate is the correct way to add one day. You must never do + (3600 * 1000 * 24)as it won’t work when DST change. 2 days in a year don’t have 24 hours but one day has 23 hours and another day has 25 hours.

Leave a Reply

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