Answer the question
In order to leave comments, you need to log in
How to get time until end of setTimeout ( Node.js )?
I write a bot in VK. I need to know the time until the end of the running timer.
I tried to equate the timer to a variable, as it was in the documentation, nothing happened.
Here is an example piece of code:
cmd.hear(/^(?:час)$/i, async (message, bot) => {
if(message.user.timer === true)
{
return bot(`Осталось: ${время setTimeout / 60 / 1000} минут.`);
}
else
{
setTimeout(() => {
message.user.timer = false;
console.log('Relog');
}, 3600000);
message.user.timer = true;
}
});
Answer the question
In order to leave comments, you need to log in
As far as I know, there is no way to find out how much time is left before the timeout is executed. At least for the reason that he himself does not know the exact time before execution, but only knows how long he cannot be performed.
But this is if we talk about pulling information out of the timeout, and of course you can:
const timerExecuteTime = Date.now() + 3600000;
When you create a timer, just in parallel also make a note somewhere about the execution time:
timer = setTimeout(function() {
// Ваш код
}, 5000);
start_time = new Date().getTime() + 5000;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question