Js实现倒计时效果

<div id="times"></div>
function _fresh() {
    var endtime = new Date("2017-10-11 16:06:00");
    var nowtime = new Date();
    var leftsecond = parseInt((endtime.getTime()-nowtime.getTime()) / 1000);
    __d = parseInt(leftsecond / 3600 / 24);
    __h = parseInt((leftsecond / 3600) % 24);
    __m = parseInt((leftsecond / 60) % 60);
    __s = parseInt(leftsecond % 60);
    document.getElementById("times").innerHTML = "" + __d + "天 " + "" + __h + "" + "小时 " + "" + __m + "" + "分 " + "" + __s + "" + "秒";
    if (leftsecond <= 0) {
    document.getElementById("times").innerHTML = "活动已结束";
    clearInterval(sh);
    }
}

var sh;
sh = setInterval(_fresh, 1000);

 

posted @ 2017-10-11 16:24  CorderBob  阅读(162)  评论(0编辑  收藏  举报