var elClock = document.getElementById("clock");
var getTime = function(){
var _ = ['00','01','02','03','04','05','06','07','08','09'], d = new Date(), h = d.getHours(), m = d.getMinutes(), s = d.getSeconds();
return [_[h]||h,_[m]||m,_[s]||s].join(":");
};
setInterval(function(){
elClock.textContent = getTime();
},1000);

<div id="clock">00:00:00</div>

==

function getintveral()
{
var d1=new Date();
var d2=new Date(2017,01,24,23,59,59);
var t1=d1.getTime();
var t2=d2.getTime();
var t3=parseInt(parseInt(t2-t1)/1000);
var d=parseInt(t3/86400);
var h=parseInt((t3-(d*86400))/3600);
var m=parseInt((t3-(d*86400)-(h*3600))/60);
var s=parseInt(t3-(d*86400)-(h*3600)-(m*60));
timer.innerHTML=d+"天"+h+"小时"+m+"分"+s+"秒";
}
timer.style.cssText="background:red"
setInterval(getintveral,1000);

 posted on 2016-12-14 10:11  jayruan  阅读(108)  评论(0编辑  收藏  举报