新闻资讯
使用JS写一个倒计时
function g(id){
return document.getElementById(id);
}
function daojishi(){
var endtime = "20150909"
var nowDate = new Date();
var endTime = new Date(endtime.substr(0,4),endtime.substr(4,2),endtime.substr(6,2),23,59,59);
var timecha = endTime.getTime() - nowDate.getTime();
if(timecha <= 0){
g(ProjectEndTime).innerHTML = "00天00时00分00秒结束";
return;
}
var days = Math.floor(timecha/(24*3600*1000));
var leave1 = timecha%(24*3600*1000);//计算天数后剩余的毫秒数
var hours = Math.floor(leave1/(3600*1000));
var leave2 = leave1%(3600*1000);//计算小时数后剩余的毫秒数
var minutes = Math.floor(leave2/(60*1000));
var leave3 = leave2%(60*1000);//计算分钟数后剩余的毫秒数
var seconds = Math.floor(leave3/1000);
if(days < 9 ){
days = "0"+days;
}
if(hours < 9 ){
hours = "0"+hours;
}
if(minutes < 9 ){
minutes = "0"+minutes;
}
if(seconds < 9 ){
seconds = "0"+seconds;
}
g(ProjectEndtime).innerHTML = days+"天"+hours+"时"+minutes+"分"+seconds+"秒结束";
}
setInterval("daojishi()",1000);
回复列表