1let date = new Date();
2// add a day
3date.setDate(date.getDate() + 1);
1function addDays(date, days) {
2 var result = new Date(date);
3 result.setDate(result.getDate() + days);
4 return result;
5}
1var myCurrentDate=new Date();
2var myFutureDate=new Date(myCurrentDate);
3 myFutureDate.setDate(myFutureDate.getDate()+ 8);//myFutureDate is now 8 days in the future
1function addDays(originalDate, days){
2 cloneDate = new Date(originalDate.valueOf());
3 cloneDate.setDate(cloneDate.getDate() + days);
4 return cloneDate;
5}
6
7let appointment = new Date("February 12, 2021 00:00:00");
8let newAppointment = addDays(appointment, 7);
9
10console.log(appointment.getDate()); // 12
11console.log(newAppointment.getDate()); // 19
1Date.prototype.addDays = function(days) {
2 var date = new Date(this.valueOf());
3 date.setDate(date.getDate() + days);
4 return date;
5}