温馨提醒
如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢
本文最后更新于2023年8月15日,已超过 180天没有更新
dedecms实现XX秒前、XX分钟前、xx天前、XX周前、XX月前、XX年前的时间差显示 在新浪微博首页看到每条微博后边显示的时间并不是标准的年-月-日格式,而是经过换算的时间差,如:发表于5分钟前、发表于“2小时前”,比起标准的时间显示格式,貌似更加直观和人性化。
打开 /include/extend.func.php 在最下面加入个方法
/**
* 时间美化
*
* @access public
* @param string $time 时间戳
* @return string
*/
if(!function_exists('tranTime'))
{
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)"/}
如果你的时间格式是 2018-10-10 这种正常时间,那要这样写调用标签
[field:pubdate function="tranTime(GetMkTime(@me))"/]
{dede:field.pubdate function="tranTime(GetMkTime(@me))"/}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系客服QQ3387285338进行处理。


评论0+