我正在使用Countdownjs在我的项目中插入计数,但它返回了错误的日期。 我正在使用 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>
但是对于该日期,它返回 06 天 08 小时 50 分钟以及结果秒数。 因为它实际上应该返回超过 100 天。
事件情况下,时间跨度控制台返回以下给定内容:
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…}
最佳答案
您正在以可变单位获取所有内容,导致周和月也被添加。 按如下方式使用单位变量:
Var units = countdown.DAYS | Countdown.HOURS | Countdown.MINUTES | Countdown.SECONDS;
因此他们只会添加天、小时、分钟和秒。
关于javascript - 日期倒计时不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42817743/