离子3:具有给定毫秒的倒数计时器不会每秒循环

时间:2018-11-02 07:26:40

标签: typescript ionic-framework countdowntimer

我已经搜索了整个互联网以运行倒数计时器,但是没有找到任何解决方法

我是打字稿和离子技术的新手,我正在尝试以下操作:

var myDate = new Date();
var startDate = myDate.getTime();

var end = new Date("2018-11-09 00:00");
var endDate = end.getTime();


var finalmillis = endDate - startDate;

现在我已经将这个最终的毫秒转换为天,小时,分钟和秒

this.seconds = Math.floor(finalmillis / 1000);
this.minutes = Math.floor(this.seconds / 60);
this.hours = Math.floor(this.minutes / 60);
this.days = Math.floor(this.hours / 24);

this.hours %= 24;
this.minutes %= 60;
this.seconds %= 60;

现在我想将其显示为我正在使用以下代码的倒数计时器

startTime(){
 this.timerVar = Observable.interval(1000).subscribe(x => {
      console.log(`${this.days} ${this.hours} ${this.minutes} ${this.seconds}`)          //Doesn't loop here
 });

0 个答案:

没有答案
相关问题