倒计时
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>倒计时</title> <script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script> </head> <body> <div> 距离开奖还有: <span class="count-down-time"></span> </div> <script> $(function () { let surplus, d, h, m, s; function currentTime() { let date = new Date(); // 获取当前时间 let now = date.getTime(); // 设置截止时间 let str = "2018/11/15 12:30:00"; let end = new Date(str).getTime(); // 时间差 let leftTime = end-now; if (leftTime >= 0) { d = Math.floor(leftTime/1000/60/60/24); h = Math.floor(leftTime/1000/60/60%24); m = Math.floor(leftTime/1000/60%60); s = Math.floor(leftTime/1000%60); surplus = d + "天"+ h + "时" + m + "分" + s + "秒"; } $(".count-down-time").html(surplus) } currentTime(); setInterval(currentTime, 1000) }) </script> </body> </html>