How do I subtract minutes from a date in javascript?

后端 未结 9 2147
囚心锁ツ
囚心锁ツ 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:47

    moment.js has some really nice convenience methods to manipulate date objects

    The .subtract method, allows you to subtract a certain amount of time units from a date, by providing the amount and a timeunit string.

    var now = new Date();
    // Sun Jan 22 2017 17:12:18 GMT+0200 ...
    var olderDate = moment(now).subtract(3, 'minutes').toDate();
    // Sun Jan 22 2017 17:09:18 GMT+0200 ...
    

提交回复
热议问题