标签:
<h2 id = "show"></h2>
<script type = "text/javascript">
var show = document.getElementById(‘show‘);
function start() {
//给定时间
var Gdate = new Date(‘2016-08-18‘);
//获取当前时间
var Tdate = new Date();
//计算时间差(毫秒值)--转化为秒数 getTime()获取1970.01.01---现在的毫秒数
var seconds = (Gdate.getTime() - Tdate.getTime())/1000;
//计算天数
var day = parseInt(seconds/3600/24);
//小时
var hour = parseInt(seconds%(3600*24)/3600);
//分钟
var minute = parseInt(seconds%3600/60);
//秒数
var second = parseInt(seconds%3600%60);
//将倒计时显示在h2标签中
show.innerHTML = "距离2016-08-18日还有:" + day + "天" + hour + "小时" + minute + "分钟" + second + "秒" ;
}
setInterval(start,1000);
</script>
标签:
原文地址:http://www.cnblogs.com/zhao12354/p/5781766.html