内容复制到 /e/class/userfun.php
function user_time($tm, $num) {
if ($num == 1) {
$tm = strtotime($tm);
}
$cur_tm = time();
$dif = $cur_tm - $tm;
$pds = array('秒', '分钟', '小时', '天', '周', '个月', '年');
$lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560);
for ($v = sizeof($lngh) - 1; ($v >= 0) && (($no = $dif / $lngh[$v]) <= 1); $v--);
if ($v < 0) $v = 0;
$_tm = $cur_tm - ($dif % $lngh[$v]);
$no = floor($no);
$x = sprintf("%d%s", $no, $pds[$v]);
return $x."前";
}
使用方法:<?=user_time($r[newstime],0)?>
上一篇:帝国CMS内容页显示标题还是副标题的简单判断
下一篇:灵动标签字段调用
时间显示
帝国cms任何模板显示几年前、几天前、几小时前等代码
时间:2026-01-31 14:06:03帝国cms任何模板显示几年前、几天前、几小时前等代码









