织梦CMS时间格式实现XX秒前、XX分钟前、XX天前

打开 /include/extend.func.php 在最下面加入个方法

01/**
02 *  时间美化
03 *
04 * @access    public
05 * @param     string  $time     时间戳
06 * @return    string
07 */
08if(!function_exists('tranTime'))
09{
10    function tranTime($time)
11    {
12        $rtime = date("m-d H:i",$time);
13        $htime = date("H:i",$time);
14        $etime = time() - $time;
15        if ($etime < 1) return '刚刚';
16        $interval = array (
17            12 * 30 * 24 * 60 * 60  =>  ' 年 前',
18            30 * 24 * 60 * 60       =>  ' 个 月 前',
19            7 * 24 * 60 * 60        =>  ' 周 前',
20            24 * 60 * 60            =>  ' 天 前',
21            60 * 60                 =>  ' 小 时 前',
22            60                      =>  ' 分 钟 前',
23            1                       =>  ' 秒 前'
24        );
25        foreach($interval as $secs => $str)
26        {
27            $d = $etime / $secs;
28            if($d >= 1)
29            {
30                $r = round($d);
31                return $r . $str;
32            }
33        };
34    }
35}

调用标签写法

首页/列表页

1[field:pubdate function="tranTime(@me)"/]

内容页

{dede:field.pubdate function="tranTime(@me)"/}

如果你的时间格式是 2018-10-10 这种正常时间那要这样写调用标签

1[field:pubdate function="tranTime(GetMkTime(@me))"/]
2{dede:field.pubdate function="tranTime(GetMkTime(@me))"/}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值