~~~ function time_tran($time,$timetype=1,$showtype="Y-m-d H:i:s"){ $now_time = time(); if($timetype==2){//非时间戳,格式为 Y-m-d H:i:s $show_time = strtotime($time); }else{ $show_time = $time; } $default_time = date($showtype,$show_time); $dur = $now_time - $show_time; if($dur < 0){ return $default_time; }else{ if($dur < 60){ return $dur.'秒前'; }else{ if($dur < 3600){ return floor($dur/60).'分钟前'; }else{ if($dur < 86400){ return floor($dur/3600).'小时前'; }else{ if($dur < 259200){//3天内 return floor($dur/86400).'天前'; }else{ return $default_time; } } } } } } ~~~