首页 新闻 会员 周边 捐助

js 怎樣得到兩個日期之間得假期數量[假期為星期六和星期天]

0
悬赏园豆:50 [已解决问题] 解决于 2008-02-27 09:13
js 怎樣得到兩個日期之間得假期數量[假期為星期六和星期天]
andysun88的主页 andysun88 | 菜鸟二级 | 园豆:205
提问于:2008-02-14 17:48
< >
分享
最佳答案
0
包含两头的日期计算在内 : <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
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册