Getting tomorrow and day after tomorrow date in JavaScript


Using the Date class of JavaScript whose object new Date() returns a JavaScript date for the current day, we have to find the date of the next two days.

This is a fairly simple problem and we can achieve this with a few lines of code. At first, get today’s date −

// getting today's date
const today = new Date();

Let’s write the code for this function −

// getting today's date
const today = new Date();
// initializing tomorrow with today's date
const tomorrow = new Date(today);
// increasing a day in tomorrow and setting it to tomorrow
tomorrow.setDate(tomorrow.getDate() + 1);
const dayAfterTomorrow = new Date(today);
dayAfterTomorrow.setDate(dayAfterTomorrow.getDate() + 2);
console.log(today);
console.log(tomorrow);
console.log(dayAfterTomorrow);

Output

Following is the output in the console −

2020-08-13T17:13:26.401Z
2020-08-14T17:13:26.401Z
2020-08-15T17:13:26.401Z

Updated on: 14-Sep-2020

531 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements