我想从我的Windows日历中获得工作日。 例如
17.06.2016 - 09.05.2016 = 5
你知道怎么做吗?它有什么功能吗?
09.05.2016 - work
10.05.2016 - work
11.05.2016 - work
12.05.2016 - work
13.05.2016 - National Day "calendar" - home
14.05.2016 - Weekend - home
15.05.2016 - Weekend - home
16.05.2016 - National Day "calendar" - home
17.05.2016 - work
答案 0 :(得分:3)
您可能想要这样做:
function getWorkingDays(startDate, endDate){
var numberOfDays = 0;
var currentDate = startDate;
while (currentDate <= endDate) {
var weekDay = currentDate.getDay();
if(weekDay != 0 && weekDay != 6)
result++;
currentDate.setDate(currentDate.getDate()+1);
}
return result;
}
var begin = new Date(2016, 05, 9);
var end = new Date(2016, 06, 17);
alert(getWorkingDays(begin, end)); // this will output 5