Countdown incorrect date

1

I'm using Countdownjs to insert a count in my project but it is returning the wrong day. I'm using AngularJS, here's the directive I created for the count:

.directive('tempoPercorrido', function($interval){
        return {
            link: function(scope, element, attrs){
                var timeNow = new Date(attrs.tempoPercorrido);
                var units = countdown.ALL;
                var timespan = countdown(timeNow, null, units, 0, 0);                    

                function updateTme(){
                    var timespan = countdown(timeNow, null, units, 0, 0);
                    var dias = timespan.days <= 9 ? '0' + timespan.days.toString() : timespan.days.toString();
                    var horas = timespan.hours <= 9 ? '0' + timespan.hours.toString() : timespan.hours.toString();
                    var minutos = timespan.minutes <= 9 ? '0' + timespan.minutes.toString() : timespan.minutes.toString();
                    var segundos = timespan.seconds <= 9 ? '0' + timespan.seconds.toString() : timespan.seconds.toString();

                    var contador = '<div class="dias circulo">'+ dias + '</div>'+
                           '<div class="horas circulo">'+ horas + '</div>'+
                           '<div class="minutos circulo">'+ minutos + '</div>'+
                           '<div class="segundos circulo">'+ segundos + '</div>';
                    //console.log(timespan);
                    $(element).html(contador);       
                }

                updateTme();

                $interval(function(){
                    updateTme();
                }, 1000);
            }
        }
    })

In HTML, I enter the following data:

<div class="horario_banner" tempo-percorrido="2017-10-29 00:00:00"></div>

But for this date it is returning 06 days 08 hours 50 min and the resulting seconds. Being that it should actually return more than 100 days.

If the timespan console is active it returns the following data:

n {start: Sun Oct 29 2017 00:00:00 GMT-0200 (Brazilian Daylight Time), end: Wed Mar 15 2017 15:11:13 GMT-0300 (Brazil's official time), units: 2047 , value: -19640926732, millennia: 0 ...}

    
asked by anonymous 15.03.2017 / 19:21

2 answers

2

You are getting everything in the variable units, causing the week and month to be added as well. Use the units variable as follows:

var units = countdown.DAYS | countdown.HOURS | countdown.MINUTES | countdown.SECONDS;

This will only add days, hours, minutes, and seconds.

    
16.03.2017 / 11:56
-1

Test here my brother ..:)

link

<!-- Display the countdown timer in an element -->
<p id="demo"></p>

<script>
// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2019 15:37:25").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get todays date and time
  var now = new Date().getTime();

  // Find the distance between now and the count down date
  var distance = countDownDate - now;

  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);

  // Display the result in the element with id="demo"
  document.getElementById("demo").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";

  // If the count down is finished, write some text 
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);
</script>
    
21.11.2018 / 03:11