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

2021年4月23日09:17:53 发表评论
微信搜一搜 ts小陈

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

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

  1. /**
  2.  *  时间美化
  3.  *
  4.  * @access    public
  5.  * @param     string  $time     时间戳
  6.  * @return    string
  7.  */
  8. if(!function_exists('tranTime'))
  9. {
  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)"/]

内容页

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

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

  1. [field:pubdate function="tranTime(GetMkTime(@me))"/]
  2. {dede:field.pubdate function="tranTime(GetMkTime(@me))"/}

 

 

 

 

小陈号卡
ts小陈

发表评论(不允许含有网址!)

:?: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :cry: :mrgreen: :neutral: :razz:

已登录用户不需要填写以下内容