Getting the date of next Monday

前端 未结 9 491
臣服心动
臣服心动 2020-12-02 23:06

How can I get the next Monday in JavaScript? I can\'t find anything of this in the internet and I have also tried a lot of codes and understanding of this but I can\'t reall

9条回答
  •  春和景丽
    2020-12-02 23:42

    This will give next Monday if today is Monday

    var d = new Date();
    d.setDate(d.getDate() + (7-d.getDay())%7+1);
    

    This will result in today if today is Monday

    var d = new Date();
    d.setDate(d.getDate() + ((7-d.getDay())%7+1) % 7);
    

提交回复
热议问题