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

摘要: /extend/function.php 最下方新增以下代码,if (!function_exists('diy_format_time'))摘要: /extend/function.php 最下方新增以下代码,if (!function_exists('diy_format_time'))

a5c27d1ed21b0ef41bd55d18168946da81cb39db906d.jpg

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


原贴: https://www.eyoucms.com/ask/list_1_10/13578.html

文章版权及转载声明:

编辑:小秋同学本文地址:https://www.qiuhai.com/study/5694.html发布于 02-21 18:02:38
文章转载或复制请以超链接形式并注明出处学习吧_一个不错的学习网站
本站文章如没有特殊说明,均采集网上收集,若要转载请务必注明出处,尊重他人劳动成果共创和谐网络环境。 声明:某些文章来源于网络,所采集的到信息本站只为传递信息和分享,不做任何双方证明,也不承担任何法律责任。 文章内容若侵犯你的权益,请联系本站客服删除!

觉得文章有用就施舍一下文章作者

支付宝施舍

微施舍

阅读
分享

发表评论
加载中~