JS implementation countdown (days, hours, minutes, seconds), js days
The example in this article explains the detailed process of JS countdown for your reference. The specific content is as follows:
Note:
The parseInt () function parses a string and returns an integer.
Syntax:
ParseInt (string, radix)
Example:
ParseInt ("10"); // returns 10 parseInt ("19", 10); // returns 19 (10 + 9) parseInt ("11", 2 ); // returns 3 (2 + 1) parseInt ("17", 8); // returns 15 (8 + 7) parseInt ("1f", 16 ); // return 31 (16 + 15) parseInt ("010"); // Undetermined: return 10 or 8
Implement countdown code
Html code:
<! DOCTYPE html>
Javascript code:
<Script language = "javascript" type = "text/javascript"> function leftTimer (year, month, day, hour, minute, second) {var leftTime = (new Date (year, month-1, day, hour, minute, second)-(new Date (); // calculate the remaining milliseconds var days = parseInt (leftTime/1000/60/60/24, 10); // calculate the remaining days var hours = parseInt (leftTime/1000/60/60% 24, 10 ); // calculate the remaining hours var minutes = parseInt (leftTime/1000/60% 60, 10); // calculate the remaining minutes var seconds = parseInt (leftTime/1000% 60, 10 ); // calculate the remaining seconds days = checkTime (days); hours = checkTime (hours); minutes = checkTime (minutes); seconds = checkTime (seconds ); setInterval ("leftTimer (1000,)",); document. getElementById ("timer "). innerHTML = days + "day" + hours + "Hour" + minutes + "Minute" + seconds + "second";} function checkTime (I) {// Add 0 to the front of the 0-9 number, and Example 1 is changed to 01 if (I <10) {I = "0" + I ;}return I ;}</script>
Effect:
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.