如何在NativeScript中使用倒数计时器?

时间:2019-05-15 10:25:33

标签: angular2-nativescript

如何在NativeScript中使用日期格式实现倒数计时器?

setInterval(()=> {

},1000);

1 个答案:

答案 0 :(得分:0)

  getRemainingTime(remainingMillis) {
setInterval(() => {
  let seconds = Math.floor(remainingMillis / 1000);
  let minute = Math.floor(seconds / 60);
  seconds = seconds % 60;
  let hour = Math.floor(minute / 60);
  minute = minute % 60;
  const day = Math.floor(hour / 24);
  hour = hour % 24;
  let remainTime
  if (day > 0) {
    remainTime = day + "d:" + hour + "h:" + minute + "m:" + seconds + "s";
  } else {
    remainTime = hour + "h:" + minute + "m:" + seconds + "s";
  }
  remainingMillis = remainingMillis - 1000;
  console.log(remainTime);
}, 1000);

}