Answers for "find the time left in a settimeout()?"

0

settimeout javascript see how much time is left

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);
}
Posted by: Guest on July-21-2021
0

setTimeout but for a given time

function setToHappen(fn, date){
    return setTimeout(fn, date - Date.now());
}
Posted by: Guest on April-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language