<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>去掉周六、日的时间计算</title>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
function cal(){
var d1 = $("date1").value.split("-");
var d2 = $("date2").value.split("-");
var date1 = new Date(d1[0], d1[1]-1, d1[2]);
var date2 = new Date(d2[0], d2[1]-1, d2[2]);
var day = (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24);
var w1 = date1.getDay();
var w2 = date2.getDay();
var w = parseInt(day / 7) * 2;
w += w1 > w2 ? 2 : w1 == 0 ? 1 : 0;
$("result").value = day - w + 1;
}
</script>
</head>
<body>
<input type="text" id="date1" name="date1" value="2013-06-19" /> -
<input type="text" id="date2" name="date2" value="2013-06-24" />
<input type="text" id="result" name="result" value="" />
<input type="button" id="btn" name="btn" value="计算" οnclick="cal();" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>去掉周六、日的时间计算</title>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
function cal(){
var d1 = $("date1").value.split("-");
var d2 = $("date2").value.split("-");
var date1 = new Date(d1[0], d1[1]-1, d1[2]);
var date2 = new Date(d2[0], d2[1]-1, d2[2]);
var day = (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24);
var w1 = date1.getDay();
var w2 = date2.getDay();
var w = parseInt(day / 7) * 2;
w += w1 > w2 ? 2 : w1 == 0 ? 1 : 0;
$("result").value = day - w + 1;
}
</script>
</head>
<body>
<input type="text" id="date1" name="date1" value="2013-06-19" /> -
<input type="text" id="date2" name="date2" value="2013-06-24" />
<input type="text" id="result" name="result" value="" />
<input type="button" id="btn" name="btn" value="计算" οnclick="cal();" />
</body>
</html>