How do I subtract minutes from a date in javascript?

后端 未结 9 2143
囚心锁ツ
囚心锁ツ 2020-11-29 03:25

How can I translate this pseudo code into working js [don\'t worry about where the end date comes from except that it\'s a valid javascript date].

var myEndD         


        
9条回答
  •  無奈伤痛
    2020-11-29 03:53

    You can also use get and set minutes to achieve it:

    var endDate = somedate;
    
    var startdate = new Date(endDate);
    
    var durationInMinutes = 20;
    
    startdate.setMinutes(endDate.getMinutes() - durationInMinutes);
    

提交回复
热议问题