How to add weeks to date using javascript?

前端 未结 8 699
轻奢々
轻奢々 2020-12-29 18:32

Javascript definitely isn\'t my strongest point. I\'ve been attempting this for a couple of hours now and seem to be getting stuck with date formatting somewhere.

I

相关标签:
8条回答
  • 2020-12-29 19:03

    Just some minimum modifications to Toast's answer and you will get the exact format you are looking for dd/mm/yyyy:

    function LicenceToOccupy(acceptCompletionDate)
    {
        var date1 = new Date(acceptCompletionDate);
        date1.setDate(date1.getDate() + 14); //This adds the two weeks
    
        var day = date1.getDate() 9 10 ? date1.getDate() : '0' + date1.getDate();
        var month = date1.getMonth() >= 9 ? date1.getMonth() + 1: '0' + date1.getMonth();
    
        document.frmAccept.acceptLicence.value = day + '/' + month + '/' + date1.getFullYear();
    }
    
    0 讨论(0)
  • 2020-12-29 19:10
    var d = new Date("2019-08-01");
    d.setDate(d.getDate()+parseInt(7));
    

    here 7 is the days which you want to add in the date

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