php函数 ,时间格式化,刚刚,最近,几分钟前 function formattime($time){
$minute = date("H:i",$time);
$hour = date("H:i",$time);
$alltime = date("Y-m-d",$time);
$time = time() - $time;
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 * 10) {
$d = floor($time/(60*60*24));
$str = $d.'天前';
}
else {
$str = $alltime;
}
return $str;
}
|