D
D
dollar2019-04-27 16:28:07
JavaScript
dollar, 2019-04-27 16:28:07

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

3 answer(s)
A
Anton Shvets, 2019-04-27
@dollar

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.

A
Alex, 2019-04-27
@Kozack

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

A
Alexey Yarkov, 2017-03-26
@Slasherr

We kind of assigned a morningAlarmnew value to the variable =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question