Increment a date in javascript without using any libraries?

JavascriptFront End TechnologyObject Oriented Programming

To add one day to date in JS, the setDate function is the best way. You can create the following function on the Date prototype to add days to the date.

Example

Date.prototype.addDays = function(days) {
   let d = new Date(this.valueOf());
   d.setDate(d.getDate() + days);
   return d;
}
let date = new Date();
console.log(date.addDays(1));

This will log the next day.

raja
Updated on 27-Nov-2019 10:41:22

Advertisements