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

前端 未结 7 778
无人共我
无人共我 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 09:57

    setDate(dayValue)

    dayValue is an integer from 1 to 31, representing the day of the month.

    from https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Date/setDate

    The behaviour solving your problem (and mine) seems to be out of specification range.

    What seems to be needed are addDate(), addMonth(), addYear() ... functions.

提交回复
热议问题