简单倒计时js代码

//倒计时
var timer=null;
var interval = 1000;
function ShowCountDown(year,month,day,hour,minute,second,divname) {
var cc = document.getElementById(divname);
var now = new Date();
var endDate = new Date(year,month-1,day,hour,minute,second);
var leftsecond = Math.round((endDate-now)/1000);

这里你可以判断等于0时执行的事件,可以用一个封装成一个函数
if(leftsecond<0){
clearInterval(timer);
return;
}else{
//var day1=parseInt(leftsecond/(24*60*60));
var ofd=parseInt(leftsecond/3600/24);//计算天数
var ofh=parseInt((leftsecond%(3600*24))/3600);//计算小时
var ofm=parseInt((leftsecond%3600)/60);//计算分
var ofs=leftsecond%60;//计算秒
if (ofd <= 9) ofd = "0" + ofd;
if (ofh <= 9) ofh = "0" + ofh;
if (ofm <= 9) ofm = "0" + ofm;
if (ofs <= 9) ofs = "0" + ofs;
cc.innerHTML = ofd+"天"+ofh+"小时"+ofm+"分"+ofs+"秒";
}
}
timer=setInterval(function(){ShowCountDown(2017,7,10,16,27,10,'divdown1');}, interval);//传入年月日时分秒,通过ID得到存放倒计时的元素

上一篇:hive数据倾斜原因以及解决办法


下一篇:Struts2中Action取得表单数据的几种方法