Long time browser, first time asker.
I'm starting an online store that updates it's homepage every night at midnight EST. I need the transition to happen smoothly and have the site refresh automatically when the clock strikes 12 for users on the page. Similar to to sites like teefury.com and theyetee.com
Is there a script that can achieve this?
Thanks so much!
Like the similar question https://stackoverflow.com/a/21482718/1256925, you can do this the following way:
var now = new Date();
var night = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate() + 1, // the next day, ...
0, 0, 0 // ...at 00:00:00 hours
);
var msTillMidnight = night.getTime() - now.getTime();
setTimeout('document.location.refresh()', msTillMidnight);
The only difference here is the final timer that runs a script. The rest of the script works the same as in that other question.
You can change the value for var night
to the following if you want to use UTC instead of the user's local time:
var night = new Date(
now.getUTCFullYear(),
now.getUTCMonth(),
now.getUTCDate() + 1, // the next day, ...
0,
now.getTimezoneOffset(), //this returns the amount of minutes difference in timezones
0
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With