//日期间的工作日 function calculateWorkDays(fromStr, toStr, holidayArray) { var from = new Date(); var to = new Date(); var fromTime = Date.parse(fromStr); var toTime = Date.parse(toStr); from.setTime(fromTime); from.setHours(0); from.setMinutes(0); from.setSeconds(0); var orgTime = from.getTime(); to.setTime(toTime); to.setHours(0); to.setMinutes(0); to.setSeconds(0); if (from.getTime() > to.getTime()) { return 0; } //把起始日都修正到星期六 javascript的星期0始,所以+1??理 var sDayofWeek = from.getDay() + 1; var workdays = 0; if (sDayofWeek > 1 && sDayofWeek < 7) { from.setDate(from.getDate() - (sDayofWeek % 7)); workdays -= ((sDayofWeek - 2) > 0) ? sDayofWeek - 2 : 0; } // var totalDays = (to.getTime() - from.getTime()) / (1000 * 60 * 60 * 24) + 1; workdays += Math.floor(totalDays / 7) * 5; //修正最后剩余天? if ((totalDays % 7 - 2) > 0) { workdays += (totalDays % 7 - 2); } if (holidayArray != null) { for (var i = 0; i < holidayArray.length; i++) { if (holidayArray[i].getTime() > orgTime && holidayArray[i].getTime() < to.getTime()) { if (holidayArray[i].getDay() > 0 && holidayArray[i].getDay() < 6) { workdays--; } } } } return workdays; }