加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

帝国cms7.2版本实现发布时间为:几小时前、几天前等格式的方法

发布时间:2021-01-11 05:35:35 所属栏目:教程 来源:网络整理
导读:帝国cms7.2怎样实现时间为:几小时前、几天前等格式 将以下代码放到:userfun.php ?ph ?之间 function user_time($tm,$num) {if($num==1){ $tm = strtotime($tm);} $cur_tm = time(); $dif = $cur_tm-$tm; $pds = array('秒','分钟','小时','天','周','个月'

帝国cms7.2怎样实现时间为:几小时前、几天前等格式

将以下代码放到:userfun.php <?ph ?>之间

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).' (注:如果不会列表放代码,请看wareelll 在11楼的提示)

内容模板调用:<?=user_time($navinfor[newstime],0)?>

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读