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

网站建设 2022-07-27 08:13www.1681989.com免费网站
打开 /clude/extend.func.php 在最下面加入个方法 / 时间美化 @aess public @param strg $time 时间戳 @return strg / if (!function_exists( tranTime )){ function tranTime ($time) {$rtime = date( m-d H:i ,$time);$htime = date( H:i ,$time);$etime = time() - $ti […]



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

/
   时间美化
 
  @aess    public
  @param     strg  $time  	时间戳
  @return    strg
 /
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 '刚刚';
		$terval = array (
			12  30  24  60  60  =>  ' 年 前',
			30  24  60  60       =>  ' 个 月 前',
			7  24  60  60        =>  ' 周 前',
			24  60  60            =>  ' 天 前',
			60  60                 =>  ' 小 时 前',
			60                      =>  ' 分 钟 前',
			1                       =>  ' 秒 前'
		);
		foreach($terval 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)" 

Copyright © 2016-2025 www.1681989.com 推火网 版权所有 Power by