Subtracting days/months/years from a Date object

后端 未结 4 1759
我寻月下人不归
我寻月下人不归 2021-01-04 09:06
var inputDate     = \'20/4/2010\'.split(\'/\');
var dateFormatted = new Date(parseInt(inputDate[2]), parseInt(inputDate[1]), parseInt(inputDate[0]));

var expiryDate         


        
4条回答
  •  难免孤独
    2021-01-04 09:19

    A similar question has been answered here:

    How to add/subtract dates with javascript?

    Similar thing can be done for months and years.

    For e.g.

         var date = new Date('2011','01','02');
         alert('the original date is '+date);
         var newdate = new Date(date);
         newdate.setMonth(newdate.getMonth() - 7);
         var nd = new Date(newdate);
         alert('the new date is '+nd);
    

提交回复
热议问题