Answer the question
In order to leave comments, you need to log in
New day event?
Is there an event that is fired when changing to a new day in local time? That is, at midnight.
If, say, setTimeout is set to the difference between the current time and midnight, will it work accurately enough? Will it be more accurate than checking and comparing the current time every second? That is, any browser freezes will not affect this?
Answer the question
In order to leave comments, you need to log in
setTimeout guarantees that the callback will not execute before the specified number of milliseconds.
The expired timeout callbacks are called at the beginning of the event loop. Those. cannot be called before the current cycle ends.
Particularly cunning browsers generally know how to freeze timeouts in inactive tabs.
Those. well, you understand, hope for setTimeout, but check the seconds anyway.
Will influence. As well as any freezes.
I don’t know your task, but I think it would be better to run the task every minute (or second, depending on the accuracy that you need) and compare the day in the last and current iteration
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question