倒计时距离2020年春节时间
<script type="text/javascript">
function showTime(){
//设置2020年春节时间
var newyear = new Date('1 25 2020');
//获取当前时间
var date1 = new Date();
// 两个日期对象直接相减,就能获取两个日期相差的时间戳,它是以毫秒计,也就是能得出相差多少毫秒
var ms = newyear - date1;
console.log(ms);
//获取天数
var day = Math.floor(ms/1000/3600/24);
//获取小时数
var h = Math.floor(ms%(3600*24*1000)/1000/3600);
//获取分钟数
var m = Math.floor(ms%(3600*24*1000)/1000%3600/60);
//获取秒数
var s = Math.floor(ms%(3600*24*1000)/1000%3600%60);
document.body.innerHTML = '距离2020年春节还有'+day+'天'+h+'小时'+m+'分钟'+s+'秒';
}
// showTime();
setInterval(showTime,1000);
</script>