如何在具体时间在特定时区刷新页面? [英] How to refresh page on specific day at specific time in specific time zone?

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

问题描述

我正在开发一个有两个背靠背网络广播的网站。我已经使用PHP来显示应该启用和禁用按钮的时间。现在我需要使用Javascript自动刷新第一个广播前的页面,第二个广播之前和第二个广播之后。我实现了以下脚本,它在给定的时间刷新页面,但是,它不能正常工作,因为我需要它。我需要修改脚本,以便在星期日下午7:45,晚上8点和晚上8:30在EST上刷新页面。

I am developing a website that has two back to back web broadcasts. I have used PHP to display the time that the buttons should be enabled and disabled. Now I need to use Javascript to automatically refresh the page before the first broadcast, before the second broadcast and after the second broadcast. I implemented the following script and it does refresh the page at the given time, however, it doesn't work exactly as I need it to. I need to alter the script so that it refreshes the page on Sundays at 7:45pm, 8pm and 8:30pm EST only.

我正在使用修改的脚本<来自这个回答的问题的href =http://stackoverflow.com/questions/1217929/how-to-automatically-reload-a-web-page-at-a-certain-time>

I'm using a modified script 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()函数。

Then I call the refreshAt() function.

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的刷新。

Where I get confused is how to alter this script to only implement the refresh for EST on Sundays.

推荐答案

我想出来了。这是脚本:

I figured it out. Here's the script:

function refreshAt(hours, minutes, seconds, day) {
    var now = new Date();
    var then = new Date();
    var dayUTC = new Date();

    if(dayUTC.getUTCDay() == day) {

        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()函数:

And then I just call the refreshAt() function:

 refreshAt(20,00,0,1); //Will refresh the page at 8:00pm on Monday UTC or 3:00pm EST

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

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