The examples in this article share with you the precise countdown effect of milliseconds for your reference. The specific content is as follows
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <title></title> <style> div{ width: 100%; height: 50px; margin-bottom: 5px; background: yellowgreen; } </style> </head> <body> <h2> Countdown of milliseconds</h2> <div id="timer1"></div> <div id="timer2"></div> <div id="timer3"></div> <div id="timer4"></div> <script> var addTimer = function(){ var list = [], interval; return function(id,timeStamp){ if(!interval){ interval = setInterval(go,1); } list.push({ele:document.getElementById(id),time:timeStamp}); } function go() { for (var i = 0; i < list.length; i++) { list[i].ele.innerHTML = changeTimeStamp(list[i].time); if (!list[i].time) list.splice(i--, 1); } } //Paste in a unix timestamp and get the countdown function changeTimeStamp(timeStamp){ var distancetime = new Date(timeStamp*1000).getTime() - new Date().getTime(); if(distancetime > 0){ //If it is greater than 0, it means that the deadline has not been reached yet var ms = Math.floor(distancetime%1000); var sec = Math.floor(distancetime/1000%60); var min = Math.floor(distancetime/1000/60%60); var hour =Math.floor(distancetime/1000/60/60%24); if(ms<100){ ms = "0"+ ms; } if(sec<10){ sec = "0"+ sec; } if(min<10){ min = "0"+ min; } if(hour<10){ hour = "0"+ hour; } return hour + ":" +min + ":" +sec + ":" +ms; }else{ //If not, it means that the deadline has reached the end time. Return "end!" } } }(); addTimer("timer1",1451923200);//00:00 on January 5, go to Baidu for unix timestamps, and some addTimer("timer2",1451926800);//01:00 on January 5th addTimer("timer3",1451930400);//02:00 on January 5th addTimer("timer4",1452020400);//03:00 on January 6th</script> </body></html>The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.