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.