//格式化用戶留言的時間
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;
}
PHP格式化時間 原
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.