帝国cms文章发布时间显示“发布于10秒前 1周前 1个月前”的方法!

时间:2023年12月29日

/

来源:网络

/

编辑:佚名

帝国cms文章发布时间显示“发布于10秒前 1周前 1个月前”的方法!
再帝国CMS程序建站的过程中,我们会遇到很多不一样的问题,例如国cms文章发布时间如何设置为显示“发布于10秒前 1周前 1个月前”呢?下面帝国CMS模板网小编就来为大家分享国cms文章发布时间显示“发布于10秒前 1周前 1个月前”的方法,一起来看看吧:
打开 /e/class/userfun.php 文件,
添加以下代码:
function user_ago($tm,$rcs = 0) {
   $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); 
   //if($no <> 1) $pds[$v] .='s'; //+s
   $x=sprintf("%d %s",$no,$pds[$v]);
   if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm);
   return $x."前";
}
内容页调用:
<?=user_ago($navinfor[newstime])?>
列表內容模板(list.var) (*) 调用:
$listtemp = "发布时间".user_ago($r[newstime])."";
OK,到这里就完成了,是不是很简单呢?快去试试吧!
猜你需要

豫ICP备2021026617号-1  豫公网安备:41172602000185   Copyright © 2021-2028 www.78moban.com/ All Rights Reserved

本站作品均来自互联网,转载目的在于传递更多信息,并不代表本站赞同其观点和对其真实性负责。如有侵犯您的版权,请联系 1565229909#qq.com(把#改成@),我们将立即处理。