
JS倒计时:
1. // 倒计时
2. let end_time = "结束时间戳"
3. countDown(end_time)
4. function countDown(end_time) {
5. let now_time = new Date().getTime()
6. let times = (end_time - now_time) / 1000 // times单位为秒
7. if(times > 0){
8. day = Math.floor(times / (60 * 60 * 24));
9. hour = Math.floor(times / (60 * 60)) - (day * 24);
10. minute = Math.floor(times / 60) - (day * 24 * 60) - (hour * 60);
11. second = Math.floor(times) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
12. }else{
13. $('#countDown').text(
00:00:00:00)14. return
15. }
16. if (day <= 9) day = '0' + day;
17. if (hour <= 9) hour = '0' + hour;
18. if (minute <= 9) minute = '0' + minute;
19. if (second <= 9) second = '0' + second;
20. //
21. // alert(day+"天:"+hour+"小时:"+minute+"分钟:"+second+"秒");
22. $('#countDown').text(
${day}:${hour}:${minute}:${second})23.
24. setTimeout(()=>{
25. countDown(end_time)
26. },1000)
27. }