首页 > 代码库 > 论坛时间的处理

论坛时间的处理

function group_date_format($time){
    $time = strtotime($time);
    $currentDay = date(‘j‘,time());
    $postDay = date(‘j‘,$time);
    if($currentDay == $postDay){
        $hours = floor((time()-$time)/(60*60));
        if($hours == 0){
            $minutes = floor((time()-$time)/60);
            if($minutes<5){
                return ‘刚刚‘;
            }else{
                return $minutes.‘分钟前‘;
            }
        }else if($hours<5){
            return $hours.‘小时前‘;
        }else{
            return ‘今天‘.date(‘H:i‘,$time);
        }
    }else if($currentDay-$postDay == 1){
        return ‘昨天‘.date(‘H:i‘,$time);
    }else if($currentDay-$postDay == 2){
        return ‘前天‘.date(‘H:i‘,$time);
    }else{
        return date(‘m-d‘,$time);
    }
    
}