时间转换成几分钟前、几小时前、几天前
浏览:799 时间:2019-09-01 14:27:12
//时间转换成几分钟前、几小时前、几天前
function time_tran($the_time) {
$the_time = date("Y-m-d H:i:s", $the_time);
$now_time = date("Y-m-d H:i:s", time());
$now_time = strtotime($now_time);
$show_time = strtotime($the_time);
$dur = $now_time - $show_time;
if ($dur < 0> return $the_time;
} else {
if ($dur < 60> return $dur . '秒前';
} else {
if ($dur < 3600> return floor($dur / 60) . '分钟前';
} else {
if ($dur < 86400> return floor($dur / 3600) . '小时前';
} else {
if ($dur < 259200> return floor($dur / 86400) . '天前';
} else {
return $the_time;
}
}
}
}
}
}
标签:
时间,格式化