1. jQuery. countdown plug-in
Display format: 50 weeks, 01 days, 07 hours, 18 minutes, 41 seconds (the second is the second of running)
A page can have multiple countdown instances that can be stopped and started. It does not provide many functions, but the time format and output size can be customized.
The latest version of v2.0.2, official address http://hilios.github.io/jQuery.countdown/
For example:
Copy codeThe Code is as follows:
<Div id = "getting-started"> </div>
<Script src = "http://code.jquery.com/jquery-1.10.2.min.js" type = "text/javascript"> </script>
<Script src = "http://hilios.github.io/jQuery.countdown/javascripts/jquery.countdown.min.js"> </script>
<Script type = "text/javascript">
$ ('# Getting-started'). countdown ('2017/01', function (event ){
Certificate (this).html (event. strftime ('% w week % d day % H: % M: % s '));
});
</Script>
Output result: 50 weeks, 01 days, 07 hours, 18 minutes, 41 seconds
Note: If you need to use % D for the total number of days, the parameter description is as follows:
Copy codeThe Code is as follows:
Y: "years"
M: "months"
W: "weeks"
D: "days"
D: "totalDays"
H: "hours"
M: "minutes"
S: "seconds"
2. Display format: 00 days, 05 hours, 25 minutes, and 30 seconds from the end time (the second is the second of running)
Copy codeThe Code is as follows:
<Div id = "time" class = "time"> </div>
<Script language = javascript>
Function show_date_time (){
Window. setTimeout ("show_date_time ()", 1000 );
Target = new Date (,); // note: the parameter of the month is between 0 and 11. That is to say, if you want to set the month to August, the parameter should be 7.
Today = new Date ();
Timeold = (target. getTime ()-today. getTime ());
Sectimeold = timeolder/1000
Secondsold = Math. floor (sectimeold );
MsPerDay = 24*60x60*1000
E_daysold = timeold/msPerDay
Daysold = Math. floor (e_daysold );
E_hrsold = (e_daysold-daysold) * 24;
Hrsold = Math. floor (e_hrsold );
E_minsold = (e_hrsold-hrsold) * 60;
Minsold = Math. floor (e_hrsold-hrsold) * 60 );
Seconds = Math. floor (e_minsold-minsold) * 60 );
If (daysold <0 ){
Document. getElementById ("time"). innerHTML = "expired, countdown expired ";
}
Else {
If (daysold <10) {daysold = "0" + daysold}
If (hrsold <10) {hrsold = "0" + hrsold}
If (minsold <10) {minsold = "0" + minsold}
If (seconds <10) {seconds = "0" + seconds}
If (daysold> 0 ){
Document. getElementById ("time "). innerHTML = "the end time is also:" + daysold + "day" + hrsold + "Hour" + minsold + "Minute" + seconds + "second ";
}
Else
Document. getElementById ("time "). innerHTML = "<font color = red> the end time is as follows: "+ daysold +" day "+ hrsold +" Hour "+ minsold +" Minute "+ seconds +" second </font> "; // the end time is less than one day, red font reminder
}
}
Show_date_time ();
</Script>
3. Display format: Running for 0 years, 1 day, 0 hours, 4 minutes, 35 seconds (running seconds)
Copy codeThe Code is as follows:
<Span id = "sitetime"> </span>
<Script language = javascript>
Function siteTime (){
Window. setTimeout ("siteTime ()", 1000 );
Var seconds = 1000
Var minutes = seconds * 60
Var hours = minutes * 60
Var days = hours * 24
Var years = days * 365
Var today = new Date ()
Var todayYear = today. getFullYear ()
Var todayMonth = today. getMonth ()
Var todayDate = today. getDate ()
Var todayHour = today. getHours ()
Var todayMinute = today. getMinutes ()
Var todaySecond = today. getSeconds ()
/* Date. UTC () -- returns the number of milliseconds (timestamp) between the date object and the World Standard Time (UTC) midnight, January 1, January 1, 1970)
Year-the year of the date object, which is a four-digit year value.
An integer between month and 0-11, used as the month of the date object.
The integer between day-1-31 as the number of days of the date object.
An integer between hours-0 (midnight) and 23, used as the hour of the date object
Minutes-an integer between 0 and 59, used as the minute count of the date object
The integer between seconds-0-59, used as the number of seconds of the date object.
Microseconds-an integer between 0 and 999, used as the millisecond count of the date object */
Var t1 = Date. UTC)
Var t2 = Date. UTC (todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond)
Var diff = t2-t1
Var diffYears = Math. floor (diff/years)
Var diffDays = Math. floor (diff/days)-diffYears * 365)
Var diffHours = Math. floor (diff-(diffYears * 365 + diffDays) * days)/hours)
Var diffMinutes = Math. floor (diff-(diffYears * 365 + diffDays) * days-diffHours * hours)/minutes)
Var diffSeconds = Math. floor (diff-(diffYears * 365 + diffDays) * days-diffHours * hours-diffMinutes * minutes)/seconds)
Document. getElementById ("sitetime "). innerHTML = "running" + diffYears + "year" + diffDays + "days" + diffHours + "hours" + diffMinutes + "Minutes" + diffSeconds + "seconds"
}
SiteTime ()
</Script>