倒计时效果:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>倒计时效果</title> </head> <body> <div>倒计时:<span id="show"></span></div> <script> setInterval(function() { var endTime = new Date('2020/9/15,00:00:00');//设置结束时间 var curTime = new Date(); var leftTime = parseInt((endTime.getTime() - curTime.getTime()) / 1000);//得出秒 // console.log(leftTime); var date = parseInt(leftTime / (24 * 60 * 60)); var hours = parseInt(leftTime / (60 * 60) % 24); var minutes = parseInt(leftTime / 60 % 60); var seconds = parseInt(leftTime % 60); var show = document.getElementById('show'); show.innerHTML = date + '天' + hours + '小时' + minutes + '分钟' + seconds + '秒'; }, 1); </script> </body> </html>