两个不同日期时间的时间差(倒计时)
function time(){
var d=new Date();
var dtime=d.getTime();
var d2=new Date("2018/10/23");
var d2time=d2.getTime();
var del=d2time-dtime;
var year=Math.floor(del/1000/60/60/24/365);
var month=Math.floor(del/1000/60/60/24/30%12);
var day=Math.floor(del/1000/60/60/24%24);
var hours=Math.floor(del/1000/60/60%60);
var minutes =Math.floor(del/1000/60%60);
var seconds =Math.floor(del/1000%60);
minutes=checkTime(minutes);
seconds =checkTime(seconds);
var time = year + "年"+ month+"月"+day + "日" + hours + "时" + minutes + "分" + seconds + "秒";
document.getElementById("time").innerHTML=time;
}
function checkTime(i)
{
if (i < 10) {
i = "0" + i;
}
return i;
}
var int;//设置全局变量
function clk(){
int=setInterval(function(){time(); },1000);
}
function endclk(){
clearInterval(int);
}