Using this, for example, it is possible to create various mechanisms related to the date and time as follows.
- Get the current date and time
- Addition / subtraction of specific elapsed time
- Get any date
The syntax is below.
let dateObj = new Date();
Get tomorrow’s date
Just run the getDate () method from the instantiated variable that gets today’s date.
let today = dateObj.getDate();
You may not get the date according to the calendar just by adding 1 to today’s date obtained above.
Therefore, the Date object has a setDate () method for date calculation.
// Add the date held by dateObj by one day dateObj.setDate( dateObj.getDate() + 1 ); // Get the date of the added instance var tomorrow = dateObj.getDate();