Core code:
var time_range = function (BeginTime, Endtime, nowtime) {
var strb = Begintime.split (":");
if (strb.length!= 2) {return
false;
}
var stre = Endtime.split (":");
if (stre.length!= 2) {return
false;
}
var strn = Nowtime.split (":");
if (stre.length!= 2) {return
false;
}
var B = new Date ();
var e = new Date ();
var n = new Date ();
B.sethours (Strb[0]);
B.setminutes (strb[1]);
E.sethours (Stre[0]);
E.setminutes (stre[1]);
N.sethours (Strn[0]);
N.setminutes (strn[1]);
if (N.gettime ()-b.gettime () > 0 && n.gettime ()-e.gettime () < 0) {return
true;
} else {
alert ("Current time is:" + n.gethours () + ":" + n.getminutes () + ", not within that time range!" ");
return false;
}
}
Time_range ("21:30", "23:30", "3:22");
Effect:
In the case of the current time:
var Time_range = function (BeginTime, endtime) {var strb = Begintime.split (":");
if (strb.length!= 2) {return false;
var stre = Endtime.split (":");
if (stre.length!= 2) {return false;
var B = new Date ();
var e = new Date ();
var n = new Date ();
B.sethours (Strb[0]);
B.setminutes (strb[1]);
E.sethours (Stre[0]);
E.setminutes (stre[1]);
if (N.gettime ()-b.gettime () > 0 && n.gettime ()-e.gettime () < 0) {return true; else {alert ("Current time is:" + n.gethours () + ":" + n.getminutes () + ", not within that time range!
");
return false;
} time_range ("21:30", "23:30");