This article describes the simple countdown implementation code of js. Share it for your reference, as follows:
<div> There are still days before the end of the event<span id="day"></span>hours<span id="min"></span>minutes<span id="sec"></span>seconds</div><script type="text/javascript">var day = document.getElementById("day");var hours = document.getElementById("hours");var min = document.getElementById("min");var sec = document.getElementById("sec");var DifferenceHour = -1;var DifferenceMinute = -1;var DifferenceSecond = -1;//var Tday = new Date("07 20,2016 10:00:00") //**Countdown time point-note-note format var Tday = new Date("07/20/2016 10:00:00"); //IE: Month/Day/Year var daysms = 24 * 60 * 60 * 1000;var hoursms = 60 * 60 * 1000;var Secondms = 60 * 1000;var microsecond = 1000;function clock () { var time = new Date(); var hour = time.getHours(); var minute = time.getMinutes(); var second = time.getSeconds(); var timevalue = "" + ((hour > 12) ? hour-12:hour); timevalue += ((minute < 10) ? ":0":":") + minute; timevalue += ((second < 10) ? ":0":":") + second; timevalue += ((hour > 12) ? " PM":" AM"); // document.formnow.now.value = timevalue var convertHour = DifferenceHour; var convertMinute = DifferenceMinute; var convertSecond = DifferenceSecond; var Diffms = Tday.getTime() - time.getTime(); DifferenceHour = Math.floor(Diffms / daysms); Diffms -= DifferenceHour * daysms; DifferenceMinute = Math.floor(Diffms / hoursms); Diffms -= DifferenceMinute * hoursms; DifferenceSecond = Math.floor(Diffms / Secondms); Diffms -= DifferenceSecond * Secondms; var dSecs = Math.floor(Diffms / microsecond); if (convertHour != DifferenceHour) { day.innerHTML = DifferenceHour; } if (convertMinute != DifferenceMinute) { hours.innerHTML = DifferenceMinute; } if (convertSecond != DifferenceSecond) { min.innerHTML = DifferenceSecond; } sec.innerHTML = dSecs; // document.formnow.Tnow.value= DifferenceHour DifferenceMinute + DifferenceSecond + dSecs setTimeout("clock()", 1000);}clock();</script>For more information about JavaScript, please check this site's special topics: "Summary of JavaScript Time and Date Operation Skills", "Summary of JavaScript Switching Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Skills", "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Data Structures and Algorithm Skills", "Summary of JavaScript Traversal Algorithm and Skills" and "Summary of JavaScript Mathematical Operation Usage"
I hope this article will be helpful to everyone's JavaScript programming.