日期:2014-05-16 浏览次数:20397 次
<script> function getHour(d1,d2){ if(d1>=d2)return 0; var rtn=Math.floor(((d2-d1)/(3600*1000))/24); var temp=0; rtn=Math.floor(((d2-d1)/(3600*1000))/24); while(d1.getHours()*60+d1.getMinutes()!=d2.getHours()*60+d2.getMinutes()){ if(d1.getHours()*60+d1.getMinutes()>=9*60+30 && d1.getHours()*60+d1.getMinutes()<12*60){ temp+=0.05; } if(d1.getHours()*60+d1.getMinutes()>=13*60 && d1.getHours()*60+d1.getMinutes()<18*60+30){ temp+=0.05; } d1.setTime(d1.getTime()+0.5*3600*1000); } rtn+=Math.floor(temp/0.8); rtn+=temp%0.8; rtn=Math.floor(rtn*100)/100 alert(rtn); } getHour(new Date("2010/1/1 12:30"),new Date("2010/1/2 11:30")); getHour(new Date("2010/1/1 10:30"),new Date("2010/1/2 19:30")); getHour(new Date("2010/1/1 8:30"),new Date("2010/1/2 17:30")); </script>