个人技术分享

帝国CMS如何修改时间格式,变成几分钟,几小时教程 - 我爱模板网

该插件已经在帝国cms6.6上测试通过,至于其他版本,请自行测试。

目前支持:标签模板,列表模板,内容模板

安装说明:
把以下的内容复制到 /e/class/userfun.php 文件里(放在<?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."前";
}

使用说明:
1.在标签模板、列表模板中的调用:

 '.user_time($r[newstime],0).'

2.在内容页中调用:

<?=user_time($navinfor[newstime],0)?>