日期倒计时不正确

Incorrect date countdown

我正在使用 Countdownjs 在我的项目中插入计数,但 return 日期不对。 我正在使用 AngularJS,这是我为计数创建的指令:

.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);
            }
        }
    })

在HTML中,我输入以下数据:

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

但是对于这个日期,它是 returning 06 天 08 小时 50 分钟和由此产生的秒数。 因为它实际上应该 return 超过 100 天。

活动案例时间跨度控制台它 returns 以下给出:

n {开始:2017 年 10 月 29 日星期日 00:00:00 GMT-0200 (Horário brasileiro de verão),结束:2017 年 3 月 15 日星期三 15:11:13 GMT-0300 (Hora oficial do Brasil),单位:2047,值:-19640926732,千年:0…}

尝试使用所有参数初始化倒计时

来自 countdown.js 文档

函数倒计时(开始、结束、单位、最大值、数字){

像这样

var today = new Date();
function updateTme(){
                var timespan = countdown(today , timeNow, units, 0, 0);
                var dias = .....

看起来 countdownjs 正在按照您的预期运行。

您选择使用所有单位 (countdown.ALL),因此您应该查看其他单位(您 查看天、小时、分钟和秒)。

您的 Timespan 对象的屏幕截图还显示 7 个月零 1 周。

如果你想要 total 天数,你可以从 Timespan 对象中的毫秒数 value 中得到,例如:

var milliseconds = timespan.value * -1; // Since it's negative in your case
var seconds = milliseconds / 1000;
var minutes = seconds / 60;
var days = minutes / 1440;

您选择了可变单位的所有内容,导致周和月也被添加。 使用单位变量如下:

Var units = countdown.DAYS | Countdown.HOURS | Countdown.MINUTES | Countdown.SECONDS;

所以他们只会添加天、小时、分钟和秒。