最新消息:本站所有跳转向bbs.ykit.cn的附件将全面停止,附件已转移到https://www.qingsj.com

PHP将发布时间转化为多久前

PHP 有客 289浏览
function ChangeTime($time){
        $time = time() - $time;
        if(is_numeric($time)){  
            $value = array(  
                  "years" => 0, "days" => 0, "hours" => 0,  
                  "minutes" => 0, "seconds" => 0,  
            );  
            if($time >= 31556926){  
                  $value["years"] = floor($time/31556926);  
                  $time = ($time%31556926);
                  $t = $value["years"].'年前';  
            }  
            elseif(31556926 >$time && $time >= 86400){  
                 $value["days"] = floor($time/86400);  
                  $time = ($time%86400);
                  $t = $value["days"].'天前';  
            }  
            elseif(86400 > $time && $time >= 3600){  
                 $value["hours"] = floor($time/3600);  
                  $time = ($time%3600);
                  $t = $value["hours"].'小时前';  
            }  
            elseif(3600 > $time && $time >= 60){  
                  $value["minutes"] = floor($time/60);  
                  $time = ($time%60);
                  $t = $value["minutes"].'分钟前';  
            }else{
                $t = $time.'秒前';
            }   
            return $t;    
        }else{  
            return date('Y-m-d H:i:s',time());  
        }  
    }

转载请注明:有客帮 » PHP将发布时间转化为多久前