【发布时间】:2017-03-16 19:00:17
【问题描述】:
我正在使用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(巴西官方),单位:2047 ,值:-19640926732,千年:0…}
【问题讨论】:
-
我发现的问题,在 var 单位中,它也得到月份,而不仅仅是天、小时和分钟,问题是我不知道如何取月和取只有天、小时、分钟和秒。
标签: javascript html angularjs angularjs-directive countdown