判断无日期时间是否在时间段内
class DateTimeHelper extends Model { //判断一个时间是不是在时间段内 static function in_time_space($current,$start,$end){ $temp_result = self::compare_time($start,$end); if($temp_result == 2 || $temp_result == 3) { //小于和等于 $start_result = self::compare_time($current, $start); $end_result = self::compare_time($current, $end); if ($start_result == 1 || $start_result == 3) { if ($end_result == 2 || $end_result == 3) { return true; } } }else{ //开始时间大于结束时间,跨零点 $middle_end = '23:59:59'; $middle_start = '00:00:00'; $temp_1 = self::in_time_space($current,$start,$middle_end); $temp_2 = self::in_time_space($current,$middle_start,$end); if($temp_1 || $temp_2){ return true; } } return false; } //1 大于, 2小于 3等于 static function compare_time($current,$target){ $current_array = explode(":",$current); $target_array = explode(":",$target); for($i =0;$i<3;$i++){ if($current_array[$i] > $target_array[$i]){ return 1; }else if($current_array[$i] < $target_array[$i]){ return 2; } } return 3; } }