zoukankan      html  css  js  c++  java
  • 周末及节假日天数去掉

    //除去节假日 周末   计算工作日
    var holiday= ['2018-05-10'];
    var holidayMap={};
    function getMap(hd){
    for(var i=0;i<hd.length;i++){
    holidayMap[hd[i]]='1';
    }
    }
    function formatTen(f){
    if (parseInt(f,10)<10){
    return '0'+f;
    }
    return f;
    }
    function formateDate(date){
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    return year + "-" + formatTen(month) + "-" + formatTen(day);
    }
    function getworkday(dat,itervalByDay){
    var str=dat.split("-");
    var date=new Date();
    date.setUTCFullYear(str[0], str[1] - 1, str[2]);
    date.setUTCHours(0, 0, 0, 0);
    var millisceonds =date.getTime();
    for(var i=1;i<=itervalByDay;i++){
    millisceonds +=24*60*60*1000;
    date.setTime(millisceonds);
    if(date.getDay()==0||date.getDay()==6){
    i--;
    }else{//过滤节假日
    var d=formateDate(date);
    if(holidayMap[d]){
    i--;
    }
    }
    }
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var rq = year + "-" + formatTen(month) + "-" + formatTen(day);
    return rq;
    }
    function getNowFormatStates() {
    var date = new Date();
    var seperator1 = "-";
    var strDate = date.getDate();
    var month = parseInt(date.getMonth()) + 1;
    if (month >= 1 && month <= 9) {
    month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
    }
    var strDate = parseInt(strDate);
    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
    return currentdate;
    }
    getMap(holiday);
    var r = getworkday(getNowFormat(),3);
  • 相关阅读:
    【小米OJ-找多少个等差数列】动态规划
    【小米OJ-找出可能的合的组合】深搜(dfs)
    【小米OJ-移除k位得到最小值】栈的应用
    【小米OJ-小米兔的轨迹】顺时针蛇形矩形
    Qt常用类
    file_operations
    Proc文件系统
    memset
    Source Insight快捷键大全
    内核内存分配
  • 原文地址:https://www.cnblogs.com/web-chuanfa/p/9042427.html
Copyright © 2011-2022 走看看