PHP格式化时间

//格式化用户留言的时间
		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格式化时间)