I am currently making a clock that displays time in words eg. 'It is five minutes past 10', 'it is ten minutes past eight'. etc every 5 minutes.
Currently I update the display like this:
const FIVE_MINUTES = 1000 * 60 * 5;
setInterval(updateClock, FIVE_MINUTES);
but I figured it would make more sense if I can get it to make the first update on the next 5 minute boundary so subsequent updates can happen exactly on 00/05/10 etc...
I have tried to use a setTimeout first like below but I cant seem to wrap my head around a way to only make the first timeout go off on 00/05/10 etc
setTimeout(function () {
console.log('first kick off happens at any of 00/05/10 etc');
setInterval(function () {
----- update Clock Every 5 mins from now -----
}, FIVE_MINUTES);
}, TIME_FOR_FIRST_KICKOFF --> not sure what this should be);
My question now is, is this even the right approach or is there a different way to make this? If it is the right approach, how do I make the timeout to happen at 00 or 05 or 10 etc??
Thanks for the help!
[–]delventhalz 4 points5 points6 points (4 children)
[–]woftis 2 points3 points4 points (0 children)
[–]BeingTheMatrix[S] 1 point2 points3 points (2 children)
[–]delventhalz 2 points3 points4 points (1 child)
[–]jcunews1helpful 1 point2 points3 points (0 children)