判断无日期时间是否在时间段内
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;
}
}
用户今天 : 1
用户昨天 : 5
用户最近的7天 : 37
用户最近的30天 : 196
用户这个月 : 173
用户这一年 : 749
合计用户 : 7418
查看今天 : 1
查看昨天 : 7
查看最近7天 : 44
查看最近30天的 : 414
查看这个月 : 383
查看这一年 : 1144
合计查看 : 9308
谁是在线的 : 0