<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1></h1>
</body>
<script type="text/javascript">
var show=document.getElementsByTagName('h1')[0];
function getTime(){
//创建时间现在
var nowdate=new Date();
//2018年1月1日的时间对象
var nextDate=new Date(2018,0,1);
//分别获取两个时间点 距离1970.1.1的时间
var nowTime=nowDate.getTime();//现在距1970年的毫秒数
var nextTime=nextDate.getTime();//2018年
//根据差值可以计算出 现在距离2018年的毫秒数 进而计算出秒数(毫秒数/1000)
var dSecond=parseInt((nextTime-nowTime)/1000);
//通过现在距离2018年的秒数求出天数(秒数/(24*60*60))
       var dDay=parseInt(dSecond/(24*60*60));
       //通过现在距离2018年的秒数取余 求出 去掉天数剩下的总秒数
       var reSecond=dSecond%(24*60*60);
       //根据计算完天数剩下的秒数 求出小时数
       var dhour=parseInt(reSecond/3600);
        console.log(dhour);
        //通过计算小时 剩下的秒数 求小时数
        var reSecond1=reSecond%3600;
        var dMinute=parseInt(reSecond1/60);
        console.log(dMinute);
        //计算分钟数剩下的秒数就是我们想要的
        var nowSecond=reSecond1%60;
        show.innerHTML='距离2018年还有'+dDay+'天'+dhour+'小时'+dMinute+'分钟'+nowSecond+'秒';
}
setInternal(function(){
getTime();
},1000);
 
</script>
</html>