基于momentjs计算范围内的工作日天数

  
     //计算工作日天数 function workday_count(start,end) { var first = start.clone().endOf('week'); // end of first week var last = end.clone().startOf('week'); // start of last week var days = last.diff(first, 'days') * 5 / 7; // this will always multiply of 7 var wfirst = first.day() - start.day(); // check first week if (start.day() == 0)--wfirst; // -1 if start with sunday var wlast = end.day() - last.day(); // check last week if (end.day() == 6)--wlast; // -1 if end with saturday return parseInt(wfirst + days + wlast); // get the total }
    const daysRange = workday_count(moment(startTime), moment(endTime))

非原创,找不到来源了,感谢!
posted @ 2020-11-25 10:10  WinniVVV  阅读(833)  评论(0)    收藏  举报