您的位置:首页 > 帝国cms教程

帝国cms个性化时间显示 几天前、几小时前、几分钟前

2022-10-24 17:16:00 帝国cms教程 177

将文章的时间按发布时间个性化显示为几分钟前、几小时前、几天前、几周前、几个月前、几年前等
使用方法:


将以下代码复制到e/class/userfun.php中


在需要调用个性化时间显示的地方,将<?=$bqr[newstime]?>改为<?=user_time($bqr[newstime])?>即可
 

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."前";
}

 

 

 

相关推荐