我正在開發一個有兩個背對背網絡廣播的網站。我已經使用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