Getting the date of next Monday

前端 未结 9 515
臣服心动
臣服心动 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:32

    var closestMonday = () => {
        var curr_date = new Date(); // current date
        var day_info = 8.64e+7; // milliseconds per day
        var days_to_monday = 8 - curr_date.getDay(); // days left to closest Monday
        var monday_in_sec = curr_date.getTime() + days_to_monday * day_info; // aleary Monday in seconds from 1970 
        var next_monday = new Date(monday_in_sec); // Monday in date object
        next_monday.setHours(0,0,0);
        return next_monday;
    }
    

提交回复
热议问题