JavaScript 倒计时 xx年 xx月 xx天 xx时 xx秒
效果:
<p><span class="txt">距离四级考试还有</span><span id="downtimeD"></span><span class="txt">天</span></p>
// 倒计时的实现
function _fresh() {
var endtime = new Date('2019/6/16,9:00:00');
var nowtime = new Date();
var leftsecond = parseInt((endtime.getTime()- nowtime.getTime()) / 1000);
var _day = parseInt(leftsecond / 3600 / 24); //倒计时天
var _hour = parseInt((leftsecond / 3600) % 24);//倒计时小时
var _min = parseInt((leftsecond / 60) % 60);//倒计时分钟
var _sec = parseInt(leftsecond % 60);//倒计时秒
document.getElementById('downtimeD').innerHTML = '' + _day;//目前只用到了天数
}
_fresh();
var sh;
sh = setInterval(_fresh, 1000);