Jquery displays * day * hour * minute * second implementation time Timer

Source: Internet
Author: User

1. Use jquery to implement a time timer. How many days from the previous time period to the current time? How many minutes? How many seconds?

Html code:
Copy codeThe Code is as follows:
<Div id = "times_wrap" class = "time_num">
Distance from current time:
<Div class = "time_w">
<Span id = "time_d" class = "time"> </span> days
<Span id = "time_h" class = "time"> </span>
<Span id = "time_m" class = "time"> </span>
<Span id = "time_s" class = "time"> </span> seconds
</Div>
</Div>

<Script type = "text/javascript">
$ (Function (){

Show_time ();

});

Function show_time (){
Var time_start = new Date ("00:00:00"). getTime (); // set the start time
Var time_end = new Date (). getTime (); // set the end time (equal to the current system time)
// Calculate the time difference
Var time_distance = time_end-time_start;
If (time_distance> 0 ){
// Day/minute/Second Conversion
Var int_day = Math. floor (time_distance/86400000)
Time_distance-= int_day * 86400000;

Var int_hour = Math. floor (time_distance/3600000)
Time_distance-= int_hour* 3600000;

Var int_minute = Math. floor (time_distance/60000)
Time_distance-= int_minute * 60000;

Var int_second = Math. floor (time_distance/1000)
// When the hour, minute, and second values are singular, add zero to the front
If (int_day <10 ){
Int_day = "0" + int_day;
}
If (int_hour <10 ){
Int_hour = "0" + int_hour;
}
If (int_minute <10 ){
Int_minute = "0" + int_minute;
}
If (int_second <10 ){
Int_second = "0" + int_second;
}
// Display time
$ ("# Time_d" pai.html (int_day );
$ ("# Time_h" ).html (int_hour );
$ ("# Time_m" pai.html (int_minute );
$ ("# Time_s" ).html (int_second );

SetTimeout ("show_time ()", 1000 );

} Else {
$ ("# Time_d" pai.html ('00 ');
$ ("# Time_h" ).html ('00 ');
$ ("# Time_m" 2.16.html ('00 ');
$ ("# Time_s" 2.16.html ('00 ');

}
}
</Script>

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.