如何通过node.js

时间:2017-03-03 07:45:07

标签: node.js

我正在使用countdownjs模块

,如何通过node.js在3天后将Console.log倒计时?

1 个答案:

答案 0 :(得分:1)

以下是一个如何使用倒计时模块的小例子:

var now = new Date();
var durationInDays = 3;
var durationInMilliseconds = (durationInDays * 24 * 60 * 60 * 1000);
var future = now.getTime() + durationInMilliseconds;
var countdownInfo = countdown(now, future);

// print it once
console.log(countdownInfo.toString());


// print it every 5 seconds

function repeatedPrint() {
    setTimeout(function () {
        // you have to provide a new start date to get updated information
        countdownInfo = countdown(new Date(), future);
        console.log(countdownInfo.toString());
        repeatedPrint();
    }, 5 * 1000);
}
repeatedPrint();