刚刚、几分钟前、几小时前等
/**
* 发布时间
* return
*/
private function getTrendsTime($post_time)
{
$ranyl_time_str = '';
$cur_time = http::server('REQUEST_TIME');
$post_year = date('Y', $post_time);
$cur_year = date('Y');
$post_date = date('d', $post_time);
$cur_date = date('d');
//是否同一年
if ($post_year == $cur_year) {
//是否当天 (当天的时间记录为几分钟前、几小时前 eg 10分钟前、23小时前)
if ($post_date == $cur_date) {
$pass_second = $cur_time - $post_time;
if ($pass_second < 60) {
$ranyl_time_str = '刚刚';
} else {
$hour = $pass_second / 3600;
if ($hour >= 1) {
$ranyl_time_str = floor($hour) . "小时前";
} else {
$minute = $pass_second / 60;
$ranyl_time_str = floor($minute) . "分钟前";
}
}
} else {
//除当天以外的本年的时间记录为几月几日 几点几分,eg:2月17日 01:42
$ranyl_time_str = date('n月d日 H:i', $post_time);
}
} else {
$ranyl_time_str = date('Y年n月d日 H:i', $post_time);
}
return $ranyl_time_str;
}