JS to achieve the countdown effect (month and day time and seconds)

Source: Internet
Author: User
Tags current time eval getdate time and seconds

Before doing a lot of activity pages are used to the countdown function, so organize the next time directly with

Use the following methods

The code is as follows Copy Code

<div class= "Timer" >
<span id= "Years" &GT;00&LT;/SPAN&GT;:
<span id= "months" &GT;00&LT;/SPAN&GT;:
<span id= "Days" &GT;00&LT;/SPAN&GT:
<span id= "Hours" &GT;00&LT;/SPAN&GT;:
<span id= "Minutes" &GT;00&LT;/SPAN&GT;:
<span id= "Seconds" >00</span>
</div>

<script type= "Text/javascript" >
Get the current time of the machine
var mydate = new Date ();
Console.log (Mydate.getfullyear (), parseint (Mydate.getmonth ()) +1, Mydate.getdate (), mydate.gethours (), Mydate.getminutes (), mydate.getseconds ());

var futuredate = eval (DATE.UTC (2014, 10, 30, 12, 0, 0));
var nowdate = eval (DATE.UTC (2013, 11, 15, 16, 36, 52));
var nowdate = eval (DATE.UTC (Mydate.getfullyear (), parseint (Mydate.getmonth ()) +1, Mydate.getdate (), mydate.gethours () , Mydate.getminutes (), mydate.getseconds ());
var obj = {
Sec:document.getElementById ("Seconds"),
Mini:document.getElementById ("Minutes"),
Hour:document.getElementById ("hours"),
Day:document.getElementById ("Days"),
Day:document.getElementById ("months"),
Day:document.getElementById ("Years")
}
Fntimecountdown (futuredate, obj, nowdate, function () {
Console.log (' Time is up! ');
});
</script>

JS code is as follows

The code is as follows Copy Code

/*
* The implementation of the countdown
*/
var fntimecountdown = function (d, O, now, callback) {
var f = {
Zero:function (n) {
var n = parseint (n, 10);
if (n > 0) {
if (n <= 9) {
n = "0" + N;
}
return String (n);
} else {
return "00";
}
},
Dv:function () {
D = d | | DATE.UTC (2050, 0, 1); If no time is defined, we set the countdown date to January 1, 2050
var future = new Date (d);
var nowtime = new Date (now);
Now future seconds Difference value
var dur = Math.Round ((Future.gettime ()-nowtime.gettime ())/1000), PMS = {
SEC: "00",
Mini: "00",
Hour: "00",
Day: "00",
Month: "00",
Year: "0"
};
if (Dur > 0) {
Pms.sec = F.zero (dur% 60);
Pms.mini = Math.floor ((dur/60)) > 0? F.zero (Math.floor (DUR/60))% 60: "00";
Pms.hour = Math.floor ((dur/3600)) > 0? F.zero (Math.floor (dur/3600))% 24: "00";
Pms.day = Math.floor ((dur/86400)) > 0? F.zero (Math.floor (dur/86400))% 30: "00";
Pms.day = Math.floor ((dur/86400)) > 0? F.zero (Math.floor (dur/86400)): "00";
month, based on the actual average number of seconds per month
Pms.month = Math.floor ((dur/2629744)) > 0? F.zero (Math.floor (dur/2629744))% 12: "00";
Year, according to the return year 365 days 5:48 46 seconds
Pms.year = Math.floor ((dur/31556926)) > 0? Math.floor ((dur/31556926)): "0";
}
return to PMS;
},
Ui:function () {
if (o.sec) {
o.sec.innerhtml = F.DV (). sec;
}
if (O.mini) {
o.mini.innerhtml = F.DV (). Mini;
}
if (o.hour) {
o.hour.innerhtml = F.DV (). hour;
}
if (o.day) {
o.day.innerhtml = F.DV (). Day;
}
if (o.month) {
o.month.innerhtml = F.DV (). Month;
}
if (o.year) {
o.year.innerhtml = F.DV (). Year;
}
now = now + 1000;
if (F.DV (). Sec = = "&& f.dv ()" mini = "" && f.dv (). Hour = "" && f.dv (). Day = = "&AMP;&A" mp F.DV () Month = = "&& f.dv" (). Year = = "0") {
if (callback) {
Callback ();
}
}

SetTimeout (F.ui, 1000);
}
};
F.ui ();
};

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.