时间模板怎么把2021-8-4改成刚刚发布,一小时前,昨天发布呢?

1236次浏览 更新日期:2021-08-04 17:14:20 分类:问题求助 评论:3

时间模板怎么把2021-8-4改成刚刚发布,一小时前,昨天发布呢?

我来说两句
  • wanmei
    wanmei 2年前
    我也要改
    0
    回复
  • {format_time($v['inputtime'],1)}  直接调用
    0
    回复
  • 百度过来的。可参考。
    
    
    // 发布时间提示
    function getFormatCreateTime($createTime)
    {
        // 当天最大时间
        $todayLast = strtotime(date('Y-m-d 23:59:59'));
        $agoTimeTrue = time() - $createTime;
        $agoTime = $todayLast - $createTime;
        $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 >2 && $agoDay<=60) {
            $result = $agoDay.'天前';
        } else {
            $result = date('Y-m-d H:i:s', $createTime);
        }
        return $result;
    }
    0
    回复
作者信息
发布见解
发内容 回顶部