根据PHP日期和时间显示HTML页面

I have an event/clubs website with the pages mon.html up to sun.html. When you visit the site on a Tuesday, the mon.html page redirects to missed_mon.html and so on up to sun.html. However if you visit the site on a Tuesday before 5 AM the mon.html page when clicked on, doesn't redirect and you can view it. The same for if you visit the site on Wednesday before 5 AM. I'm trying to get the mon.html page not to be displayed once it's Wednesday regardless of whether it's 5 AM but still visible on Tuesday before 5 AM. The rule should apply to all the other pages as well i.e. if it's on a Thursday, Mon/Tue.html can't be viewed but wed.html can be viewed before 5 AM Thursday. I hope that makes sense. The code I have so far for monday is..

var d = new Date();
var s = d.getDay();
var r = d.getHours();
if ((s>1 || s==0) && (r>5)){
window.location = "http://dundaah.com/docs/missed_mon.html";
}

the sun.html page doesn't require any code and Tuesday is..

var d = new Date();
var s = d.getDay();
var r = d.getHours();
if ((s>2 || s==0) && (r>5)){
window.location = "http://dundaah.com/docs/missed_tue.html";
}

etc. thanks in advance. Changed it to a PHP solution

</div>

Save the following code as index.php in your server and browse to it, it will check the server time and it will forward to desired page. the logic for deciding the link have to be done yourself.

<?php
$timeinhour = date("H");   // get time in 24-hour format
$dayis = date("D");     //Get day in string format - eg: Mon Sun etc

//Compare your logic as required
// time between Sun 5:00 AM to Monday 4:59AM
if (($dayis = "Sun" && $timeinhour > 4 ) or ($dayis = "Mon" && $timeinhour <5))  
{

header( 'Location: link1.html'); //forward to the desired link
}
else if (($dayis = "Mon" && $timeinhour > 4 ) or ($dayis = "Tue" && $timeinhour <5))
{
header( 'Location: link2.html');
}
?>

Do this for all day-time logics you required.

Indeed, there are many scenarios but I suggest the solution below for you as i see you look for JavaScript solution .

The following Script to be at your home or index page , Note: inside body tag.

I consider that you should show the link to your page according to its time to be shown.

<script>
 var date = new Date();
 var allweek = new Array(7);
 allweek[0]=  "missed_sun.html";
 allweek[1] = "missed_mon.html";
 allweek[2] = "missed_tue.html";
 allweek[3] = "missed_wen.html";
 allweek[4] = "missed_thu.html";
 allweek[5] = "missed_fri.html";
 allweek[6] = "missed_sat.html";
 var hour     = date.getHours();
 var today    = date.getDay();
 var one ="1";
 var add = parseInt(today,10)- parseInt(one,10);
 var target   = allweek[add]; 
 var page     = allweek[today]; 

if (hour >= 0 && hour < 17){       //  here you check if only file for today  should be linked and shown or yesterday file as well
var todaylink = document.createElement('a');
var todaylinktxt = document.createTextNode("today");
todaylink .appendChild(todaylinktxt);
todaylink .href = page;
document.body.appendChild(todaylink );
var br = document.createElement('br');
document.body.appendChild(br);
var yesterdaylink = document.createElement('a');
var yesterdaytxt = document.createTextNode("yesterday");
yesterdaylink.appendChild(yesterdaytxt);
yesterdaylink.href = target;
 document.body.appendChild(yesterdaylink);
  }
   else if(hour >= 17) // here you confirm that only file for today should be   linked and shown
  {
var todaylink = document.createElement('a');
var todaylinktxt = document.createTextNode("today");
todaylink .appendChild(todaylinktxt);
todaylink .href = page;
document.body.appendChild(todaylink );
 }else{} 
</script>

Then at every page put the following script ,**Note: inside body tag**

<script>
var date = new Date();
var allweek = new Array(7);
allweek[0]=  "missed_sun.html";
allweek[1] = "missed_mon.html";
allweek[2] = "missed_tue.html";
allweek[3] = "missed_wen.html";
allweek[4] = "missed_thu.html";
allweek[5] = "missed_fri.html";
allweek[6] = "missed_sat.html";

var hour     = date.getHours();
var thisfile =location.pathname.substring(location.pathname.lastIndexOf("/") + 1);// make sure this get the exact file name like like in url ,otherwise put the name of current file as in url 
var today = date.getDay();
var one ="1";
var yesterday  = parseInt(today,10)- parseInt(one,10);
var filefortoday   = allweek[today];
var fileyesterday  = allweek[yesterday ];     

 if (thisfile == filefortoday ){                    // it means that is a day for current file , so nothing will happen

 }else if(thisfile == fileyesterday ){               // check if your current file day suppose to be yesterday

if (hour < 17){    }else{ window.location = "http://dundaah.com/docs/"+filefortoday;} // check whether it's time finished or not

 }else{ 

  window.location = "http://dundaah.com/docs/"+filefortoday;
 }
 </script>

It works fine for me , wish to help you

solved it via js

var d = new Date();
var s = d.getDay();
var r = d.getHours();
if ((s>1 || s==0) && (r>5 || s==3 || s==4 || s==5 || s==6 || s==0)){
window.location = "http://dundaah.com/docs/missed_mon.html";
}

that's for mon.html, for the rest I just remove "|| s==3 or || s==4" depending o the day

</div>