文档时间调用 改成(N年前,N月前,N天前,N小时前,N分钟前)的形式(图1)

/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个小时前,以此类推