Categories
JavaScript Answers

How to Take Today’s Date and Add 1 Day to it with JavaScript?

Spread the love

Sometimes, we want to take today’s date and add 1 day to it with JavaScript.

In this article, we’ll look at how to take today’s date and add 1 day to it with JavaScript.

Take Today’s Date and Add 1 Day to it with JavaScript

To take today’s date and add 1 day to it with JavaScript, we can create a new date with the timestamp set to 1 day after today.

To do this, we write:

const tomorrow = new Date((new Date()).valueOf() + 1000 * 3600 * 24);
console.log(tomorrow)

We add:

(new Date()).valueOf() 

to get the timestamp of today’s date time in milliseconds.

Then we add the number of milliseconds for 1 day by adding 1000 * 3600 * 24.

Then we use all that as the argument of the Date constructor.

Therefore, tomorrow is:

Sun Sep 12 2021 11:03:06 GMT-0700 (Pacific Daylight Time)

if the current date and time is Sep 11, 2021, 11:03:06 Pacific Time.

Conclusion

To take today’s date and add 1 day to it with JavaScript, we can create a new date with the timestamp set to 1 day after today.

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 *