如何在特定时间更新您的主页? [英] How to update your homepage at a certain time?

查看:79
本文介绍了如何在特定时间更新您的主页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

长时间浏览器,第一次请求.

Long time browser, first time asker.

我正在建立一个在线商店,每天晚上EST(美国东部标准时间)午夜更新其主页.我需要过渡才能顺利进行,并让页面上的用户在时钟达到12时自动刷新网站.类似于teefury.com和theyetee.com

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?

非常感谢!

推荐答案

就像类似的问题 https://stackoverflow.com/a /21482718/1256925 ,您可以通过以下方式进行操作:

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.

如果要使用UTC而不是用户的本地时间,可以将var night的值更改为以下值:

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
);

这篇关于如何在特定时间更新您的主页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆