/extend/function.php 最下方新增以下代码,
if (!function_exists('diy_format_time')) { function diy_format_time($date) { $timeDifference = getTime() - $date; $timeUnits = [ ['label' => '年前', 'seconds' => 60 * 60 * 24 * 365], ['label' => '月前', 'seconds' => 60 * 60 * 24 * 30], ['label' => '天前', 'seconds' => 60 * 60 * 24], ['label' => '小时前', 'seconds' => 60 * 60], ['label' => '分钟前', 'seconds' => 60] ]; foreach ($timeUnits as $unit) { if ($timeDifference >= $unit['seconds']) { $count = floor($timeDifference / $unit['seconds']); return $count . $unit['label']; } } return '刚刚'; } }
{$field.add_time|diy_format_time=###} 发布时间
{$field.update_time|diy_format_time=###} 更新时间
逻辑如下
1分钟之内的 显示刚刚,超过1分钟的显示分钟数前,超过60分钟的显示 1个小时前,以此类推
未经允许不得转载! 作者:小秋同学,转载或复制请以超链接形式并注明出处XQ 筑站派。
原文地址:《文档时间调用 改成(N年前,N月前,N天前,N小时前,N分钟前)的形式》发布于:2025-02-21 18:02:38