小编跟大家分享一个当前时间是否在设定的时间段,像特定时间段签到、抢红包等等,都能用的到,上代码。
function public time_quantum(){
//当前年月日
$Date = date('Y-m-d ',time());
//年月日拼接开始时间
$Begin1 = strtotime($Date."08:00".":00");
//年月日拼接截止时间
$End1 = strtotime($Date."10:00".":00");
//开始时间
$Begin2 = strtotime($Date."11:00".":00");
//截止时间
$End2 = strtotime($Date."13:00".":00");
//开始时间
$Begin3 = strtotime($Date."16:00".":00");
//截止时间
$End3 = strtotime($Date."18:00".":00");
//当前时间
$curr_time = time();
//使用逻辑与判断当前时间在哪个时间段
if($curr_time >= $Begin1 && $curr_time <= $End1){
return 0;
}elseif($curr_time >= $tBegin2 && $curr_time <= $End2){
return 1;
}elseif($curr_time >= $Begin3 && $curr_time <= $End3){
return 2;
}else{
return 3;
}
}
有什么不懂的地方,请大家指出来,谢谢ヾ(◍°∇°◍)ノ゙