倒计时

    var remainTime = Date.parse('2016/01/01');
    var minites = 1000 * 60;
    var hours = minites * 60;
    var days = hours * 24;

    setInterval(function () {
        var nowGetTime = new Date().getTime();

        var sDays = Math.floor((remainTime - nowGetTime) / days);
        var sHours = Math.floor((remainTime - nowGetTime - sDays * days) / hours);
        var sMinites = Math.floor((remainTime - nowGetTime - sDays * days - sHours * hours) / minites);
        var sSecondes = Math.floor((remainTime - nowGetTime - sDays * days - sHours * hours - sMinites * minites) / 1000);

        document.getElementById('timer').innerHTML = '距离2016年1月1日还有' + sDays + '天' + sHours + '小时'  + sMinites + '分'  + sSecondes + '秒';
    }, 1000);

你可能感兴趣的:(原生javascript)