JS implementation of the countdown to the Web page, the site has run the time function of the Code 3 cases _javascript Skills

Source: Internet
Author: User
Tags diff

1, Jquery.countdown Plug-ins

Display format: 50 weeks 01 days 07 hours 18 minutes 41 seconds (seconds to run seconds)
A page can have multiple countdown instances, can stop and start, it does not provide too many features, but the time format and output size can be customized.
The latest edition v2.0.2, official address http://hilios.github.io/jQuery.countdown/
For example:

Copy Code code 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 (' 2016/01/01 00:00 ', function (event) {
$ (this). html (event.strftime ('%w weeks%d days%h:%m:%s '));
});
</script>

Output results: 50 weeks 01 days 07 hours 18 minutes 41 seconds

Note: If you need a total number of days with%d, parameter description:

Copy Code code as follows:

Y: "Years"
M: "Months"
W: "Weeks"
D: "Days"
D: "Totaldays"

H: "Hours"
M: "Minutes"
S: "Seconds"


2, display format: Distance end time also: 00 days 05 hours 25 minutes 30 seconds (seconds for running seconds)

Copy Code code as follows:

<div id= "Time" class= "Time" ></div>
<script language=javascript>
function Show_date_time () {
Window.settimeout ("Show_date_time ()", 1000);
Target=new Date (2014,0,15,17,0,0); Note: The parameters that represent the month are between 0 and 11. In other words, if you want to set the month to August, the argument should be 7.
Today=new Date ();

Timeold= (Target.gettime ()-today.gettime ());

sectimeold=timeold/1000
Secondsold=math.floor (Sectimeold);
msperday=24*60*60*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= "Overdue, the countdown has 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 distance is also:" +daysold+ "Days" +hrsold+ "hours" +minsold+ "minutes" +seconds+ "seconds";
}
Else
document.getElementById ("Time"). Innerhtml= "<font color=red> distance End times also:" +daysold+ "Day" +hrsold+ "hours" +minsold+ "points"  +seconds+ "SEC </font>"; End time is less than 1 days, the font is red alert
}
}
Show_date_time ();
</script>

3, display format: has been running 0 years 1 days 0 hours 4 minutes 35 seconds (seconds for running seconds)

Copy Code code 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 midnight of the Date object from World Standard Time (UTC) January 1, 1970
Year-years as Date object, 4-bit year value
Integer between month-0-11, as the month of the date object
Integer between day-1-31, number of days as Date object
Hours-0 (24 O'Clock Midnight)-an integer between 23, the number of hours as the date object
Integer between minutes-0-59, number of minutes as Date object
The integer between seconds-0-59, the number of seconds as the date object
The integer between microseconds-0-999, the number of milliseconds to be the date object.
var T1 = DATE.UTC (2014,0,14,11,19,00)
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= "has run" +diffyears+ "+diffdays+" Days "+diffhours+" hours "+diffminutes+" minutes " +diffseconds+ "Seconds"
}
Sitetime ()
</script>

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.