Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在特定时区的特定日期、特定时间刷新页面?_Javascript_Date_Timezone_Refresh - Fatal编程技术网

Javascript 如何在特定时区的特定日期、特定时间刷新页面?

Javascript 如何在特定时区的特定日期、特定时间刷新页面?,javascript,date,timezone,refresh,Javascript,Date,Timezone,Refresh,我正在开发一个网站,有两个背靠背的网络广播。我使用PHP来显示按钮的启用和禁用时间。现在我需要使用Javascript在第一次广播之前、第二次广播之前和第二次广播之后自动刷新页面。我实现了下面的脚本,它确实在给定的时间刷新页面,但是,它不能完全按照我的需要工作。我需要修改脚本,使其刷新页面在周日晚上7:45,晚上8点和晚上8:30美国东部时间只有 我正在使用修改过的脚本 然后我调用refreshAt函数 refreshAt(19,45,0); //Will refresh the page at

我正在开发一个网站,有两个背靠背的网络广播。我使用PHP来显示按钮的启用和禁用时间。现在我需要使用Javascript在第一次广播之前、第二次广播之前和第二次广播之后自动刷新页面。我实现了下面的脚本,它确实在给定的时间刷新页面,但是,它不能完全按照我的需要工作。我需要修改脚本,使其刷新页面在周日晚上7:45,晚上8点和晚上8:30美国东部时间只有

我正在使用修改过的脚本

然后我调用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刷新。

您甚至可以在一周中的某一天添加测试,例如:

now.getDay() == "Sunday"

另一种方法是使用。这将保持与接收事件的开放连接

包括Pusher javascript:

<script src="http://js.pusher.com/1.11/pusher.min.js"></script>
然后在晚上8点或任何时候,您需要在推送器控制面板页面上手动发出推送器事件,当前查看该页面的所有人都将重新加载

function refreshAt(day, hours, minutes, seconds) 
{
    Date.getDay() = day
...
}

0是星期天,6是星期六

我明白了。以下是脚本:

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

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

我和你有同样的问题。我正在建立一个听起来很像你的网站,还使用PHP在广播时间前后启用和禁用页面元素。您的解决方案似乎很有希望,但最终我对使用纯Javascript重新加载页面感到不满。Javascript从客户机获取时间,而PHP从服务器获取时间,两者之间的微小差异可能会破坏整个系统。i、 页面可能会在PHP启用按钮前30秒刷新,导致一些观众认为整个页面已经关闭

我通过使用PHP告诉Javascript函数现在是什么时间来解决这个问题,它的工作方式很有魅力。唯一的问题是它每天都在运行,而不是一周中的某一天,但这并不困扰我-用户除了在广播日之外没有理由查看页面

这就是你所需要的-我把它放在标签后面:


很抱歉,这个答案质量不高。如果你愿意的话,我会再编辑一下。我是通过电话接听的,所以质量不是一流的。这对我将来制作的东西真的很有用。谢谢分享!hi@stacigh,如果没有day变量,这会是什么样子,我试着自己做,但javascript不是我的拿手好戏。我的目标是每天在格林尼治标准时间刷新。谢谢
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(20,00,0,1); //Will refresh the page at 8:00pm on Monday UTC or 3:00pm EST
<script type="text/javascript">
setTimeout(function() { window.location.reload(true); }, 1000*<?php 
$then = mktime(15,00,0);
$tomorrow = mktime(15, 00, 0, date("m") , date("d")+1);
$now = time(); 
if ($now > $then) {echo $tomorrow - $now;}
else {echo $then - $now;}?>); </script>