Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update your homepage at a certain time?

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 image 229
Dennis Menzel Avatar asked Feb 02 '14 15:02

Dennis Menzel


1 Answers

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
);
like image 168
Joeytje50 Avatar answered Sep 21 '22 19:09

Joeytje50