5 Replies Latest reply on Mar 18, 2015 7:27 AM by Kirchgässner

    Counter, countdown problems

    Kirchgässner Level 1

      Hi there

       

      I want to create a counter that counts down to this friday march 20. 11 pm. But the counter show 33 days when publishing it. What could be the problem? Heres my code:

       

      //Change this as per your requirement

      var until = new Date(Date.UTC(2015, 3, 19, 0, 0, 0));var $dd = sym.$("dd");

      var $hh = sym.$("hh");

      var $mm = sym.$("mm");

      var $ss = sym.$("ss");

       

       

      function pad(num, size) {

          var s = num+"";

          while (s.length < size) s = "0" + s;

          return s;

      }

       

       

      function startCounter() {

        updateCounter();

        setInterval(updateCounter, 1000);

      }

       

       

      function updateCounter() {

        var now = new Date();

        var delta = until - now;

       

       

        var days  = Math.floor( delta / (86400000) );

        var hours = Math.floor( delta / (3600000) );

        var mins  = Math.floor( delta / (60000) );

        var secs  = Math.floor( delta / 1000 );

       

       

        var dd = days;

        var hh = hours - days  * 24;

        var mm = mins - hours * 60;

        var ss = secs - mins  * 60;

       

       

        $dd.html(pad(dd,2));

        $hh.html(pad(hh,2));

        $mm.html(pad(mm,2));

        $ss.html(pad(ss,2));

      }

       

       

      startCounter();