javascript date + 7 days

前端 未结 10 671
孤城傲影
孤城傲影 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:47

    var future = new Date(); // get today date
    future.setDate(future.getDate() + 7); // add 7 days
    var finalDate = future.getFullYear() +'-'+ ((future.getMonth() + 1) < 10 ? '0' : '') + (future.getMonth() + 1) +'-'+ future.getDate();
    console.log(finalDate);

提交回复
热议问题