How do I refresh the page automatically every 15 minutes based on clock time?
For example: refresh on 9:00, 9:15, 9:30, 9:45, 10:00, 10:15, so on..
I have seen one similar like I wanted : https://stackoverflow.com/a/1217945/551559 but I don't think it does the job.
setInterval(function(){
// check clock time on every minute??
if ( clock_time === '9:15' ) {
}
},1000);
Can someone give me a solution or any link to look at?
You can use the modulus operator to work out if we're in a multiple of 15 minutes
I am not sure if you want it to reload after every 15 minutes regardless of when started. But if you need to access the local time and get the current hours and minutes use this:
You could check it like this:
Hope it helps.
Call this function on page load or via any other trigger, it will set the timeout for the page to reload exactly when it hits xx.[00|15|30|45].00
Explaining if(!minutes%15) :
minutes % 15
is a modulo operation. It will divide minutes by 15 and return the rest. So if the result is 0, it means that minutes is a multiple of 15.Now we need to invert that value : 0 is equivalent to false, so we want !0 (not zero = true)
Finally we get
if( ! minutes % 15 )
will be true if minutes is a multiple of 15.If it has to be in the script use set Timeout like