<p id="timeTxt"></p>
<script type="text/javascript">
function add(m){
return m<10 ? "0"+m : m;
}
var time2 = new Date().getTime();
function getTime(time){
var nowTime = new Date("2018-12-15 12:30:00").getTime();
var TimeCon = (nowTime - time)/1000;
TimeCon = parseInt(TimeCon);
var d = parseInt(TimeCon/(60*60*24));
var h = parseInt(TimeCon/(60*60)%24);
var m = parseInt(TimeCon/60%60);
var s = parseInt(TimeCon%60);
return d+"天"+add(h)+"小时"+add(m)+"分钟"+add(s)+"秒";
}
setInterval(function(){
var that = this;
time2 +=1000;
console.log(time2);
document.getElementById("timeTxt").innerHTML = that.getTime(time2);
console.log(that.getTime(time2));
},1000);
</script>