Categories
JavaScript Answers

How to add 3 days in milliseconds to current Date with JavaScript?

Spread the love

Sometimes, we want to add 3 days in milliseconds to current Date with JavaScript.

In this article, we’ll look at how to add 3 days in milliseconds to current Date with JavaScript.

How to add 3 days in milliseconds to current Date with JavaScript?

To add 3 days in milliseconds to current Date with JavaScript, we pass in the timestamp for 3 days after today into the Date constructor.

For instance, we write

const dateObj = new Date(Date.now() + 86400000 * 3);

to call Date.now to get the timestamp of the current date time.

Then we add 3 days, which is 86400000 * 3 ms to it.

And we use the sum as the argument of the Date constructor to return a Date object with the date 3 days from now.

Conclusion

To add 3 days in milliseconds to current Date with JavaScript, we pass in the timestamp for 3 days after today into the Date constructor.

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 *