您好,欢迎访问一九零五行业门户网

时间格式转换有关问题

时间格式转换问题
2013-11-01 22:26:56
怎样把上面的时间格式转换成3秒前或3天前这种格式显示
分享到: 更多
------解决方案--------------------
http://www.baidu.com/s?wd=smarty%e6%a8%a1%e6%9d%bf%e5%87%bd%e6%95%b0&ie=utf-8
------解决方案--------------------
引用:quote: 引用:
http://www.baidu.com/s?wd=smarty%e6%a8%a1%e6%9d%bf%e5%87%bd%e6%95%b0&ie=utf-8
看了还是不太明白,能讲详细点吗?比如下面这段代码修改成 smarty模板函数要怎样修改?
function sgmdate($dateformat, $format=0) {     $result = '';     if($format) {         $time = time() - $dateformat;         if($time > 24*3600) {             $result = date('y-m-d',$dateformat);         } elseif ($time > 3600) {             $result = intval($time/3600).'小时前';         } elseif ($time > 60) {             $result = intval($time/60).'分钟前';         } elseif ($time > 0) {             $result = $time.'秒前前';         } else {             $result = '刚刚';         }     } else {         $result = date('y-m-d',$dateformat);     }     return $result; }
还有在模板代码中如何调用,怎样修改,模板源代码如下:
smarty模板引擎
那你就在你的php文件里找到
$tpl -> assign(home, $home);
在这个之前加下面这么一句就ok:
$home['regtime']=sgmdate($home['regtime'],1);
其它类似信息

推荐信息