js 取時間差去掉周六周日

來源:互聯網
上載者:User

function GetDayNum(no,type) {        if (type == "35") {                var num7 = document.getElementById("6").value;                var value = document.getElementById("7").value;                var valueR = num7;                if (no == "7") {valueR = value;}//標識時間值                if (num7 != "" && value != "") {//兩個時間段可以融合 BUG1                    var numValue = 0;                    var numValue = 0;                    var day = 24 * 60 * 60 * 1000;                    var dateArr = value.split("-");                    var checkDate = new Date();                    checkDate.setFullYear(dateArr[0], dateArr[1] - 1, dateArr[2]);                    var checkTime = checkDate.getTime();                    var dateArr2 = num7.split("-");                    var checkDate2 = new Date();                    checkDate2.setFullYear(dateArr2[0], dateArr2[1] - 1, dateArr2[2]);                    var checkTime2 = checkDate2.getTime();                    var numValue = (checkTime - checkTime2) / day; //相差的總天數                     var totleWeek = numValue / 7; //差別多少周                    var yuDay = numValue % 7; //除了整個星期的天數                    var lastDay = 0;                    var startWeek = num7.replace(/-/g, "/");  //把“-”改為“/”,其中“-”算時間不準確這個我測試了                    //var date = new Date(parseInt(startWeek[0]), parseInt(startWeek[1]), parseInt(startWeek[2]));                    var date = Date.parse(startWeek);                    var dateNew = new Date(date);                    var weekDay = dateNew.getDay(); //星期幾                    var endWeekDay = 0;   //多餘的天數有幾天是周六或者周日                    if ((weekDay == 6 && yuDay >= 2) || (weekDay == 7 && yuDay >= 1) || (weekDay == 5 && yuDay >= 3) || (weekDay == 4 && yuDay >= 4) || (weekDay == 3 && yuDay >= 5) || (weekDay == 2 && yuDay >= 6) || (weekDay == 1 && yuDay >= 7)) {                        endWeekDay = 2;www.2cto.com                    }                    if ((weekDay == 6 && yuDay < 1) || (weekDay == 7 && yuDay < 5) || (weekDay == 5 && yuDay < 2) || (weekDay == 4 && yuDay < 3) || (weekDay == 3 && yuDay < 4) || (weekDay == 2 && yuDay < 5) || (weekDay == 1 && yuDay < 6)) {                        endWeekDay = 1;                    }                  //  if (numValue == 0) { numValue = 1; }                    numValue = numValue - (totleWeek * 2) - endWeekDay; //最終時間                                                                               }        }    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.