SetInterval for longer hours

Is the SetInterval method reliable for a longer time? I have a requirement to run functions once every day and / or once a week. So I use setInterval(myFunc, 86400000) // For one day. similarly calculated number of milliseconds in one week. This is a good approach. or is there any other method that I can use.

+4
source share
2 answers

I think a good option would be

when a web page opens, first save the date in local storage, when its open usually check the date in local storage every minute and then check it and take action.

setIterval sounds like a very bad way to do it here ...

When you start, get the data,

save the date using localStorage.setItem("date", datevariblename);

at boot time or every time you use the set interval localStorage.getItem("date") to get the date value

Then do what is required for each sort between the current date and the save date.

+1
source

setTimeout pretty accurate for longer periods of time. Some time ago I had this requirement, so I did some testing in browsers. Even if you have a timeout that lasts, for example, 24 hours, the callback works exactly (the deviation is in the region of milliseconds).

setTimeout (or more precisely, implementation) does not use a "countdown". He will ask the operating system to give it SIG nal when the time period is completed.

0
source

All Articles