Skip to content

Instantly share code, notes, and snippets.

@ambercouch
Last active March 22, 2023 18:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ambercouch/f45889db6435299bba22ea1ee6e06d31 to your computer and use it in GitHub Desktop.
Save ambercouch/f45889db6435299bba22ea1ee6e06d31 to your computer and use it in GitHub Desktop.
Refresh the browser and a specific time (23:00:00)
function refreshAt(hours, minutes, seconds) {
var now = new Date();
var then = new Date();
if(now.getHours() > hours ||
(now.getHours() == hours && now.getMinutes() > minutes) ||
now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
then.setDate(now.getDate() + 1);
}
then.setHours(hours);
then.setMinutes(minutes);
then.setSeconds(seconds);
var timeout = (then.getTime() - now.getTime());
setTimeout(function() { window.location.reload(true); }, timeout);
}
//refresh the page at 23:00:00
refreshAt(23,00,0);
@faisalhzh-id
Copy link

Thanks Brother

@ajashams
Copy link

This works perfectly. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment