• 日期间隔(除去周六、日)


        //日期间的工作日
        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;
    
        }
  • 相关阅读:
    ES集群性能调优链接汇总
    【转】dmesg 时间转换
    广师大笔记汉诺塔
    广师大python学习笔记求派的值
    155. 最小栈(c++)
    160. 相交链表(c++)
    论文 数据集总结
    论文阅读 总结 复习
    121. 买卖股票的最佳时机(c++)
    9. 回文数(c++)
  • 原文地址:https://www.cnblogs.com/chirifengye/p/2981998.html
Copyright © 2020-2023  润新知