帝國(guó)cms7.2怎樣實(shí)現(xiàn)時(shí)間為:幾小時(shí)前、幾天前等格式
將以下代碼放到:userfun.php <?ph ?>之間
function user_time($tm,$num) {if($num==1){ $tm = strtotime($tm);} $cur_tm = time(); $dif = $cur_tm-$tm; $pds = array('秒','分鐘','小時(shí)','天','周','個(gè)月','年'); $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."前";}列表模板調(diào)用:'.user_time($r[newstime],0).' (注:如果不會(huì)列表放代碼,請(qǐng)看wareelll 在11樓的提示)
內(nèi)容模板調(diào)用:<?=user_time($navinfor[newstime],0)?>
新聞熱點(diǎn)
疑難解答
圖片精選