//格式化用户留言的时间
function settime($msg){
foreach($msg as $key=>$val){
$time=time();
$oldtime=$val['time'];
$currenttime=$time-$oldtime;
$rtime = date("m-d H:i",$oldtime);
$htime = date("H:i",$oldtime);
if($currenttime<60){
$msg[$key]['timemsg']='刚刚';
}elseif($currenttime < 60 * 60){
$min = floor($currenttime/60);
$msg[$key]['timemsg']=$min.'分钟前';
}elseif($currenttime < 60 * 60 * 24){
$h = floor($currenttime/(60*60));
$msg[$key]['timemsg']=$h.'小时前 '.$htime;
}elseif($currenttime < 60 * 60 * 24 * 3){
$d = floor($currenttime/(60*60*24));
if($d==1){
$msg[$key]['timemsg']='昨天 '.$rtime;
}else{
$msg[$key]['timemsg']='前天 '.$rtime;
}
}else{
$msg[$key]['timemsg']=$rtime;
}
}
return $msg;
}
转载于:https://my.oschina.net/itudou/blog/116161