<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <meta charset="UTF-8"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>下班倒计时</title> </head> <body> <div id="msg"> </div> </body> </html> <script> var endTime = new Date(); endTime.setHours(9); endTime.setMinutes(29); endTime.setSeconds(52); var getTime = function() { var nowTime = new Date(); var ms = endTime.getTime() - nowTime.getTime(); var day = Math.floor(ms / (1000 * 60 * 60 * 24)); var hour = Math.floor(ms / (1000 * 60 * 60)) % 24; var minute = Math.floor(ms / (1000 * 60)) % 60; var second = Math.floor(ms / 1000) % 60; ms = Math.floor(ms / 100) % 10; if (day >= 0) { document.getElementById("msg").innerHTML = hour + "小时 " + minute + "分 " + second + " 秒" } else { alert("下班了"); return false; } setTimeout("getTime()", 1000); } getTime(); </script>
时间: 2024-12-28 11:17:50