JS countdown Simple Implementation Code _JAVASCRIPT skills

Source: Internet
Author: User
Tags set time

Countdown:

1. Set a valid end date

2. Calculate the remaining time

3. Convert time to available format

4. Output clock data as a reusable object

5. Display the clock on the page and stop when it arrives 0 o'clock

Html

<div id= "Clock" >
  <span id= "Days" ></span> day
  <span id= "Hours" ></span>

  <span id= "Minutes" ></span>

  <span id= "Seconds" ></span> sec

</div>


JS Code

<script><br>/* Calculate the remaining time/function Gettimereamin (endtime) {//remaining number of seconds Var remainsec= (Date.parse (endtime)-D
    Ate.parse (New Date ())/1000;
    var Days=math.floor (remainsec/(3600*24));
    var hours=math.floor (remainsec/3600%24);
    var minutes=math.floor (remainsec/60%60);
    var seconds=math.floor (remainsec%60);
  return{"Remainsec": Remainsec, "Days":d ays, "hours": Hours, "minutes": minutes, "seconds": seconds}
var endtime= "2016/10/10";
var Clock=document.getelementbyid ("clock");
  Set timer var timeid=setinterval (function () {var t=gettimereamin (endtime); Judge time format days= t.days>=0&& t.days<10? "
  0 "+t.days:t.days; hours= t.hours>=0&& t.hours<10? "
  0 "+t.hours:t.hours; Minutes=t.minutes>=0&&t.minutes<10? "
  0 "+t.minutes:t.minutes; Seconds=t.seconds>=0&&t.seconds<10? "
  0 "+t.seconds:t.seconds;
  Set time document.getElementById ("Days"). Innertext= Day; document.getElementById ("hours"). InnerText= hours;
  document.getElementById ("Minutes"). innertext= minutes;
  document.getElementById ("seconds"). Innertext=seconds;
  Clears the timer if (t.remainsec<=0) {clearinterval (Timeid);
}
}); 

 <script>

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.