JavaScript Countdown Timer to specific time everyday

前端 未结 2 473
余生分开走
余生分开走 2021-01-27 17:14

I am currently developing a website with a countdown timer at the headline: http://iphone.myhandykey.com/

The current timer is just 12hrs + few mins.. What I would like

2条回答
  •  佛祖请我去吃肉
    2021-01-27 17:51

    Something like this:

        $(document).ready(function () {
            var mg = new Date(2016, 5, 21, 0, 0, 0, 0);
            var tmr = window.setInterval(function () {
                var d = new Date();
                var dif = mg - d;
                var s = parseInt(dif / 1000);
    if (s < 0) {
        document.getElementById('spCnt').innerHTML = 'Event starts';
        window.clearInterval(tmr);
        return;
    }
                var sec = s % 60;
                var m = parseInt(s / 60);
                var min = m % 60;
                var h = parseInt(m / 60);
                var hour = h % 24;
                d = parseInt(h / 24);
    
                document.getElementById('spCnt').innerHTML = d + ' days ' + hour + ' hours ' + min + ' min and ' + sec + ' sec remaining';
            }, 1000);
        });
    

提交回复
热议问题