📜  settimeout javascript 查看还剩多少时间 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:12.756000             🧑  作者: Mango

代码示例1
var timeout = setTimeout(function() {}, 3600 * 1000);

setInterval(function() {
    console.log('Time left: '+getTimeLeft(timeout)+'s');
}, 2000);

function getTimeLeft(timeout) {
    return Math.ceil((timeout._idleStart + timeout._idleTimeout - Date.now()) / 1000);
}