判断无日期时间是否在时间段内
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;
}
}
用户今天 : 3
用户昨天 : 15
用户最近的7天 : 69
用户最近的30天 : 283
用户这个月 : 229
用户这一年 : 4357
合计用户 : 6149
查看今天 : 7
查看昨天 : 15
查看最近7天 : 74
查看最近30天的 : 306
查看这个月 : 242
查看这一年 : 4829
合计查看 : 7484
谁是在线的 : 0