Home > Web Front-end > JS Tutorial > body text

js 取时间差去掉周六周日实现代码_javascript技巧

WBOY
Release: 2016-05-16 17:45:44
Original
1355 people have browsed it
复制代码 代码如下:

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.jb51.net
}
if ((weekDay == 6 && yuDay endWeekDay = 1;
}
// if (numValue == 0) { numValue = 1; }
numValue = numValue - (totleWeek * 2) - endWeekDay; //最终时间

}
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!