我正在开发一个有两个背对背网络广播的网站。我已经使用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的刷新。
hi @stacigh,没有日变量,这会是什么样子,试图做自己,但JavaScript不是我的东西。我的目标是每天更新GMT时间。谢谢! – Jaypee 2015-05-14 22:42:41