包含两头的日期计算在内 :
<script type="text/javascript">
function weekendBetween(dtStart, dtEnd) {
if (typeof dtEnd == 'string' )
dtEnd = StringToDate(dtEnd);
if (typeof dtStart == 'string' )
dtStart = StringToDate(dtStart);
var days = parseInt((dtEnd - dtStart) / 86400000);
var adds = 0;
var m = (days+ dtStart.getDay() +1) % 7;
if(m > 0)
adds = m;
if(m >2)
adds = 2;
var redu = 0
if(dtStart.getDay() > 0)
redu = 2;
if(dtStart.getDay() ==1)
redu =1;
var subtotal = parseInt((days + dtStart.getDay() +1)/7)*2;
return subtotal - redu + adds;
}
function StringToDate(DateStr)
{
var converted = Date.parse(DateStr);
var myDate = new Date(converted);
if (isNaN(myDate))
{
var arys= DateStr.split('-');
myDate = new Date(arys[0],arys[1],arys[2]);
}
return myDate;
}
alert("2-1~~~~2-18");
alert(weekendBetween(new Date(2008,2,1), new Date(2008,2,18)));
alert("2-1~~~~2-15, 字符型参数");
alert(weekendBetween("2008-2-1","2008-2-15"));
alert("2-1~~~~2-16, 字符型参数");
alert(weekendBetween("2008-2-1","2008-2-16"));
alert("2-1~~~~2-17, 字符型参数");
alert(weekendBetween("2008-2-1","2008-2-17"));
alert("2-3~~~~2-16, 字符型参数");
alert(weekendBetween("2008-2-3","2008-2-16"));
</script>
沙加
|
老鸟四级
|园豆:3680
|
2008-02-14 23:49