美文网首页
告别枯燥的时间格式,人性化显示时间片段

告别枯燥的时间格式,人性化显示时间片段

作者: Chting | 来源:发表于2018-06-15 10:43 被阅读0次
public function formatTime($time='')
{     
    $rtime = date("m-d H:i",$time);       
    $htime = date("H:i",$time);             
    $time = time() - $time;   
    $str='';      
    if ($time < 60){           
        $str = '刚刚';       
    }elseif($time < 60 * 60){           
        $min = floor($time/60);           
        $str = $min.'分钟前';       
    }elseif($time < 60 * 60 * 24){           
        $h = floor($time/(60*60));           
        $str = $h.'小时前 ';       
    }elseif($time < 60 * 60 * 24 * 3){           
        $d = floor($time/(60*60*24));           
        if($d==1){  
            $str = '昨天 '.$htime;  
        }else{  
            $str = '前天 '.$htime;       
        }  
    }else{           
        $str = $rtime;       
    }       
    return $str;   

}

相关文章

网友评论

      本文标题:告别枯燥的时间格式,人性化显示时间片段

      本文链接:https://www.haomeiwen.com/subject/nuppeftx.html