Answer the question
In order to leave comments, you need to log in
How to find out how much time is left before the timer expires?
var timer = setTimeout(alert('Hello world!'), 32*60*1000);
setInterval(function(){
var timeout = ;//нужно получить время
console.log('Timeout через: '+timeout);
}, 1000)
Answer the question
In order to leave comments, you need to log in
It is possible like this:
var duration = 32 * 60 * 1000;
var step = 1000;
var endsAfter = duration;
var timer = setTimeout(alert, duration, 'Hello world!');
var interval = setInterval(function() {
endsAfter -= step;
if (endsAfter <= 0) clearInterval(interval);
console.log('Timeout через: ', endsAfter);
}, step);
In fact, no way, because setTimeout adds a task to macroTaskQueue and this does not mean that it will be executed every second. Find out the approximate time - as written above: when setting setTimeout, remember (time stamp + timeout value) and subtract the current timestamp from setInterval from it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question