天天看点

php格式化时间缀函数

<?php

/

function:显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前

timeInt:unix time时间戳

format:时间显示格式

*/

function timeFormat($timeInt,$format='Y-m-d H:i:s'){

if(empty($timeInt)||!is_numeric($timeInt)||!$timeInt){

return '';

}

$d=time()-$timeInt;

if($d<0){

}else{

if($d<60){

return $d.'秒前';

if($d<3600){

return floor($d/60).'分钟前';

if($d<86400){

return floor($d/3600).'小时前';

if($d<259200){//3天内

return floor($d/86400).'天前';

return date($format,$timeInt);

本文转自 Lee_吉  博客,原文链接:     http://blog.51cto.com/12173069/2048672   如需转载请自行联系原作者