【发布时间】:2012-02-05 12:31:46
【问题描述】:
我正在开发一个有两个背靠背网络广播的网站。我使用 PHP 来显示应该启用和禁用按钮的时间。现在我需要使用Javascript在第一次广播之前,第二次广播之前和第二次广播之后自动刷新页面。我实现了以下脚本,它确实在给定时间刷新了页面,但是,它并不能完全按照我的需要工作。我需要更改脚本,使其仅在美国东部标准时间周日晚上 7 点 45 分、晚上 8 点和晚上 8 点 30 分刷新页面。
我正在使用修改后的脚本from this answered question
function refreshAt(hours, minutes, seconds) {
var now = new Date();
var then = new Date();
if(now.getUTCHours() > hours ||
(now.getUTCHours() == hours && now.getUTCMinutes() > minutes) ||
now.getUTCHours() == hours && now.getUTCMinutes() == minutes && now.getUTCSeconds() >= seconds) {
then.setUTCDate(now.getUTCDate() + 1);
}
then.setUTCHours(hours);
then.setUTCMinutes(minutes);
then.setUTCSeconds(seconds);
var timeout = (then.getTime() - now.getTime());
setTimeout(function() { window.location.reload(true); }, timeout);
}
然后我调用 refreshAt() 函数。
refreshAt(19,45,0); //Will refresh the page at 7:45pm
refreshAt(20,00,0); //Will refresh the page at 8:00pm
refreshAt(20,30,0); //Will refresh the page at 8:30pm
我感到困惑的是如何更改此脚本以仅在周日为 EST 实现刷新。
【问题讨论】:
标签: javascript date timezone refresh