How do I subtract minutes from a date in javascript?

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

    Everything is just ticks, no need to memorize methods...

    var aMinuteAgo = new Date( Date.now() - 1000 * 60 );
    

    or

    var aMinuteLess = new Date( someDate.getTime() - 1000 * 60 );
    

    update

    After working with momentjs, I have to say this is an amazing library you should check out. It is true that ticks work in many cases making your code very tiny and you should try to make your code as small as possible for what you need to do. But for anything complicated, use momentjs.

提交回复
热议问题