日期:2014-05-16 浏览次数:20401 次
<!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"> window.onload = function() { document.getElementById('btn_calc').onclick = function() { var obj = document.getElementById('demo').getElementsByTagName('input'); var ar_ds = obj[0].value.split('-'); var ar_ts = obj[1].value.split(':'); var ds = new Date(ar_ds[0], ar_ds[1] - 1, ar_ds[2], ar_ts[0], ar_ts[1]); var ar_de = obj[2].value.split('-'); var ar_te = obj[3].value.split(':'); var de = new Date(ar_de[0], ar_de[1] - 1, ar_de[2], ar_te[0], ar_te[1]); var result = de.getTime() - ds.getTime(); //开始、结束是否超过24小时,超过减15个小时乘天数 if (result > 86400000) result -= Math.floor(result / 86400000) * 54000000; document.getElementById('result').innerHTML = '请假时间:' + (result / 3600000).toFixed(1) + '小时'; } } </script> </head> <body> <div id="demo"> 开始日期:<input type="text" value="2012-05-23" /> 开始时间:<input type="text" value="08:30" /><br /> 结束日期:<input type="text" value="2012-05-24" /> 结束时间:<input type="text" value="17:30" /><br /> <button id="btn_calc">计算</button> </div> <div id="result"></div> </body> </html>