Javascript 特定服务器时间或本地时间后的Url重定向

Javascript 特定服务器时间或本地时间后的Url重定向,javascript,html,redirect,time,Javascript,Html,Redirect,Time,我试图让一个HTML页面在一天中的某个时间后自动重定向到同一域上的另一个URL 例如: Date.prototype.today=函数(){ return((this.getDate()=“今天上午8:16”) { location.href=”http://www.youtube.com"; } 其他的 { location.href=“index.html”; } 您可以在新日期使用并比较: var time = Date.now(); if (time < new Date()

我试图让一个HTML页面在一天中的某个时间后自动重定向到同一域上的另一个URL

例如:


Date.prototype.today=函数(){
return((this.getDate()<10)?“0”:“”)+this.getDate()+“/”+((this.getMonth()+1)<10)?“0”:“”)+(this.getMonth()+1)+“/”+this.getFullYear();
}
如果((新日期().today())>=“今日12:26PM”)
{
location.href=”http://www.google.com";
}
其他的
{
location.href=“index.html”;
}
如果((新日期().today())>=“今天下午4:26”)
{
location.href=”http://www.Hotmail.com";
}
其他的
{
location.href=“index.html”;
}
如果((新日期().today())>=“今天上午8:16”)
{
location.href=”http://www.youtube.com";
}
其他的
{
location.href=“index.html”;
}
您可以在新日期使用并比较:

var time = Date.now();

if (time < new Date().setHours(12, 0, 0, 0)) { // Before 12
  location.href = "http://www.google.com";
} else if (time < new Date().setHours(16, 0, 0, 0)) { // 12 to 4pm
  location.href = "http://www.hotmail.com";
} else if (time < new Date().setHours(20, 0, 0, 0)) {  // 4pm to 8pm
  location.href = "http://www.youtube.com";
} else {
  location.href = "index.html"; // 8 pmon wards
}
var time=Date.now();
如果(时间<新日期().setHours(12,0,0,0)){//在12之前
location.href=”http://www.google.com";
}如果(时间
您是要根据小时重定向页面,还是只在特定时间重定向页面?例如,在下午4点到5点之间的任何一天重定向到youtube,或者您只想在10月16日之后重定向到youtube,然后再重定向到hotmail?每天下午4点到5点之间重定向到example.com