/*
@desc:显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前
@param stamp 时间戳
@param format 时间显示格式,默认Y-m-d H:i:s
*/
function timefriend($stamp,$format = 'Y-m-d H:i:s'){
if(empty($stamp)||!is_numeric($stamp)||!$stamp){
return '—';
}
$diff = time()-$stamp;
if($diff<0){
return '';
}elseif($diff<60){
return $diff.'秒前';
}elseif($diff<3600){
return floor($diff/60).'分钟前';
}elseif($diff<86400){
return floor($diff/3600).'小时前';
}elseif($diff<259200){
return floor($diff/86400).'天前';
}else{
return date($format,$stamp);
}
}
$ret = timefriend('128541570');
echo $ret;
1974-01-28 01:59:30