What's the simplest way to decrement a date in Javascript by 1 day?

前端 未结 7 744
无人共我
无人共我 2020-12-17 09:30

I need to decrement a Javascript date by 1 day, so that it rolls back across months/years correctly. That is, if I have a date of \'Today\', I want to get the date for \'Ye

相关标签:
7条回答
  • 2020-12-17 10:18

    getDate()-1 should do the trick

    Quick example:

    var day = new Date( "January 1 2008" );
    day.setDate(day.getDate() -1);
    alert(day);
    
    0 讨论(0)
提交回复
热议问题