首页 > IT职业 > IT生活 > 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
return '';
}else{
if($d
return $d.'秒前';
}else{
if($d
return floor($d/60).'分钟前';
}else{
if($d
return floor($d/3600).'小时前';
}else{
if($d
return floor($d/86400).'天前';
}else{
return date($format,$timeInt);
}
}
}
}
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4365/viewspace-2801391/ ,如需转载,请注明出处,否则将追究法律责任。