javascript date + 7 days

前端 未结 10 685
孤城傲影
孤城傲影 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 15:00

    var date = new Date();
    date.setDate(date.getDate() + 7);
    
    console.log(date);

    And yes, this also works if date.getDate() + 7 is greater than the last day of the month. See MDN for more information.

提交回复
热议问题