本文主要是介绍织梦CMS时间格式实现XX秒前、XX分钟前、XX天前,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
打开 /include/extend.func.php 在最下面加入个方法
05 | * @param string $ time 时间戳 |
08 | if (!function_exists( 'tranTime' )) |
10 | function tranTime($ time ) |
12 | $rtime = date ( "m-d H:i" ,$ time ); |
13 | $htime = date ( "H:i" ,$ time ); |
14 | $etime = time () - $ time ; |
15 | if ($etime < 1) return '刚刚' ; |
17 | 12 * 30 * 24 * 60 * 60 => ' 年 前' , |
18 | 30 * 24 * 60 * 60 => ' 个 月 前' , |
19 | 7 * 24 * 60 * 60 => ' 周 前' , |
20 | 24 * 60 * 60 => ' 天 前' , |
25 | foreach($interval as $secs => $str) |
|
调用标签写法
首页/列表页
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))" /} |
|
这篇关于织梦CMS时间格式实现XX秒前、XX分钟前、XX天前的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!