javascript date + 7 days

前端 未结 10 701
孤城傲影
孤城傲影 2020-12-02 14:18

What\'s wrong with this script?

When I set my clock to say 29/04/2011 it adds 36/4/2011 in the week input! but the correct date should be 6/

10条回答
  •  盖世英雄少女心
    2020-12-02 14:50

    var days = 7;
    var date = new Date();
    var res = date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    
    var d = new Date(res);
    var month = d.getMonth() + 1;
    var day = d.getDate();
    
    var output = d.getFullYear() + '/' +
        (month < 10 ? '0' : '') + month + '/' +
        (day < 10 ? '0' : '') + day;
    
    $('#txtEndDate').val(output);
    

提交回复
热议问题