HomeTutorsContact

JavaScript get tomorrow's date

By Gulshan Saini
Published in JavaScript
December 13, 2021
1 min read

Working with dates in JavaScript can get a little tricky. I will show you how you can add 1 day to the current date to get tomorrow’s date. This even works when the month changes.

How to get tomorrow’s date using JavaScript

  1. First, we store today’s date in a variable
let today = new Date();
  1. Next, we create another variable tomorrow and pass the today variable inside the Date constructor
let tomorrow = new Date(today);
  1. And, then we use the setDate method on tomorrow variable to add 1 day to it. We do this by first getting the current date using tomorrow.getDate() and adding 1 to it.
tomorrow.setDate(tomorrow.getDate() + 1) // 1639464689038

This would return us a numeric value like 1639464689038 which is Unix epoch time

Similarily, if you want to set hours or reset it to 00:00:00 then you can call the setHours(0,0,0,0) method as follows

tomorrow.setDate(tomorrow.getDate() + 1)
tomorrow.setHours(0,0,0,0)

So without using any heavy library in your existing codebase you can easily add one date to the current date and get tomorrow’s date using JavaScript.

👉 If you found this post useful, bookmark this page (⌘ + d / ctrl + d) for your future reference 😃


Tags

#javascript
Previous Article
React - HTTP Get request using browser fetch API

Related Posts

JavaScript
Double exclamation mark !! (not not) operator in JavaScript?
December 09, 2021
1 min
Gulshan Saini

Gulshan Saini

Fullstack Developer

Topics

Angular
JavaScript
ReactJS
Typescript
Linux

Subscribe to our newsletter!

We'll send you the best of our blog just once a month. We promise.

Quick Links

Contact UsBrowserCSSPythonPuppeteer

Social Media