01: 时间戳转化为几天前
/**
* 时间转化为几天前,几小时前
*/
function tranTime2($time){
$time = intval($time);
$nowTime = time();
$t = $nowTime - $time;// 时间差
if($t<=10){
$str = '刚刚';
}else if($t>10 && $t<=60){
$str = $t . '秒前';
}else if($t>60 && $t<=60*60){
$str = floor($t/60) . '分钟前';
}else if($t>60*60 && $t<=60*60*24){
$str = floor($t/(60*60)) . '小时前';
}else if($t>60*60*24 && $t<=60*60*24*7){
$str = floor($t/(60*60*24)) . '天前';
}else if($t>60*60*24*7 && $t<=60*60*24*7*4){
$str = floor($t/(60*60*24*7)) . '周前';
}else if($t>60*60*24*7*4 && $t<=60*60*24*365){
$nowM = date('m',$nowTime);
$m = date('m',$time);
if($nowM<$m){
$str = (12-$m) + $nowM . '个月前';
}else{
$str = $nowM - $m . '个月前';
}
}else if($t>60*60*24*365){
$str = date('Y',$nowTime) - date('Y',$time) . '年前';
}
return $str;
}
网友评论