Javascript subtracting days from date

前端 未结 1 507
南笙
南笙 2020-12-10 17:11

This code where I subtract days from a date does not get the right results.

function get_Ash_Wednesday_date (year, Easter_month, Easter_day) {
    var Easter         


        
相关标签:
1条回答
  • 2020-12-10 17:44

    Saw a note in the references not to pass negative values to setDate().

    Try this instead:

    var Ash_Wednesday = new Date (  
        Easter_date.getFullYear(),  
        Easter_date.getMonth(),  
        (Easter_date.getDate()-46)  
    )
    

    This solution Finding date by subtracting X number of days from a particular date in Javascript doesn't seem to work any longer

    0 讨论(0)
提交回复
热议问题