原生js倒计时和显示当前时间

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>当前时间显示 </title>

</head>
<body onload="startTime()">
<div id="time"></div>
<h2 id="lasttime"></h2>
<h2 id="lasttime1"></h2>
</body>
<script type="text/javascript">

function startTime()
{
var today=new Date()
var endtime = new Date('12 10,15 22:00:00').getTime();
var nowtime = new Date().getTime();
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()

var myyear=today.getFullYear();
var mymonth=today.getMonth();
var monthArray=["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]
var mynowdate=today.getDate();
var myday=today.getDay();
var dayArray=["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]

var lasttime=endtime-nowtime;

    var Tint=1000*60*60*24;
var Hint=1000*60*60;
var Mint=1000*60;
var nowT=parseInt(lasttime/(1000*60*60*24));
var nowH=parseInt((lasttime-(Tint*nowT))/(1000*60*60));
var nowMin=parseInt((lasttime-(Tint*nowT)-(Hint*nowH))/(1000*60));
var nowS=parseInt((lasttime-(Tint*nowT)-(Hint*nowH)-(Mint*nowMin))/1000);

    
m=checkTime(m)
s=checkTime(s)
document.getElementById('time').innerHTML=myyear+""+monthArray[mymonth]+mynowdate+""+dayArray[myday]+h+":"+m+":"+s;
document.getElementById('lasttime').innerHTML=nowT+""+nowH+"小时"+nowMin+"分钟"+nowS+"";
setTimeout('startTime()',1000);
}


function checkTime(i)
{
if (i<10) 
  {i="0" + i}
  return i
}

</script>
</html>

 

posted @ 2015-12-10 18:18  djdliu  阅读(444)  评论(0编辑  收藏  举报