function TimeAgo( $ptime ) {
$ptime = strtotime($ptime);
$etime = time() - $ptime;
if($etime < 1) return '刚刚';
$interval = array (
12 * 30 * 24 * 60 * 60 => '年前 ('.date('Y-m-d', $ptime).')',
30 * 24 * 60 * 60 => '个月前 ('.date('m-d', $ptime).')',
7 * 24 * 60 * 60 => '周前 ('.date('m-d', $ptime).')',
24 * 60 * 60 => '天前',
60 * 60 => '小时前',
60 => '分钟前',
1 => '秒前'
);
foreach ($interval as $secs => $str) {
$d = $etime / $secs;
if ($d >= 1) {
$r = round($d);
return $r . $str;
}
};}
把以上代码放在你主题下的include.php文件中,如果你的主题没有include.php文件,那么请手动建一个,格式如下:
{TimeAgo($article.Time())}
标签:24,ptime,ZBlog,etime,60,XX,天前,date From: https://www.cnblogs.com/hwrex/p/18378922