DedeCms織夢釋出內容時間格式實現XX秒前、XX分鐘前
阿新 • • 發佈:2018-11-19
在include/extend.func.php最下面新增
function tranTime($time) { $rtime = date("m-d H:i",$time); $htime = date("H:i",$time); $etime = time() - $time; if ($etime < 1) return '剛剛'; $interval = array ( 12 * 30 * 24 * 60 * 60 => ' 年 前', 30 * 24 * 60 * 60 => ' 個 月 前', 7 * 24 * 60 * 60 => ' 周 前', 24 * 60 * 60 => ' 天 前', 60 * 60 => ' 小 時 前', 60 => ' 分 鍾 前', 1 => ' 秒 前' ); foreach ($interval as $secs => $str) { $d = $etime / $secs; if ($d >= 1) { $r = round($d); return $r . $str; } }; }
前臺模板呼叫標籤
首頁/列表頁
[field:pubdate function=tranTime(@me)/]
內容頁
{dede:field.pubdate function=tranTime(@me)/}