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>