JS implementation countdown (days, hours, minutes, seconds), js days

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.