php 发布时间提示

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_39191303/article/details/89639153

<?php

//发布时间提示
function get_last_time($time)
{
    // 当天最大时间
    $todayLast = strtotime(date('Y-m-d 23:59:59'));
    $agoTimeTrue = time() - $time;
    $agoTime = $todayLast - $time;
    $agoDay = floor($agoTime / 86400);
    if ($agoTimeTrue < 60) {
        $result = '刚刚';
    } elseif ($agoTimeTrue < 3600) {
        $result = (ceil($agoTimeTrue / 60)) . '分钟前';
    } elseif ($agoTimeTrue < 3600 * 12) {
        $result = (ceil($agoTimeTrue / 3600)) . '小时前';
    } elseif ($agoDay == 1) {
        $result = '昨天 ';
    } elseif ($agoDay == 2) {
        $result = '前天 ';
    } elseif($agoDay >= 7 && $agoDay <= 14){
        $result = '上周 ';
    } elseif($agoDay >= 30 && $agoDay <= 60){
        $result = '上个月 ';
    }else {
        $format = date('Y') != date('Y', $time) ? "Y-m-d" : "m-d";
        $result = date($format, $time);
    }
    return $result;
}
echo get_last_time(time());

?>

猜你喜欢

转载自blog.csdn.net/qq_39191303/article/details/89639153