JS Implementation countdown (Days, hours, minutes, seconds) _javascript skills

Source: Internet
Author: User

The example of this article for everyone to parse the countdown to the detailed process of JS, for everyone's reference, the specific contents are as follows

Comments:
The parseint () function parses a string and returns an integer.
Syntax:
parseint (string, radix)

Cases:

parseint ("10"); Returns ten
parseint ("19", 10);//Return (10+9)
parseint ("11", 2);//Return 3 (2+1)
parseint ("17", 8);//Return 15 (8+7)
parseint ("1f", 16);//Return to (16+15)
parseint ("010");//undecided: return 10 or 8

Implementing the 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 = par Seint (LEFTTIME/1000/60/60/24, 10); Calculate the remaining days 
 var hours = parseint (lefttime/1000/60/60% 24, 10);//Calculate remaining hours 
 var minutes = parseint (lefttime/1 000/60% 60, 10);//Calculate remaining minutes 
 var seconds = parseint (lefttime/1000% 60, 10);//Calculate the number of seconds remaining 
 = Checktime (days); 
   hours = Checktime (hours); 
 minutes = Checktime (minutes); 
 seconds = checktime (seconds); 
 SetInterval ("Lefttimer (2016,11,11,11,11,11)", 1000); 
 document.getElementById ("Timer"). InnerHTML = days+ "Day" + hours+ "hour" + minutes+ "minutes" +seconds+ "seconds"; 
} 
function Checktime (i) {//0-9 of the number preceded by 0, example 1 changes to 
 if (i<10) 
 { 
  i = "0" + i; 
 } 
 return i; 
} 
 
</script> 

Implementation effect:

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.