thinkcmf5评论显示几天前,几小时前,几分钟前的代码

thinkcmf5评论显示几天前,几小时前,几分钟前的代码:
 
一.在simplewind\cmf\common.php加入公共方法
 
/*
* 时间戳用来转成xx前
*/
function ChangeTime($time)
{
$time = time() - $time;
if (is_numeric($time)) {
$value = array(
"years" => 0, "days" => 0, "hours" => 0,
"minutes" => 0, "seconds" => 0,
);
if ($time >= 31556926) {
$value["years"] = floor($time / 31556926);
$time = ($time % 31556926);
$t = $value["years"] . '年前';
} elseif (31556926 > $time && $time >= 86400) {
$value["days"] = floor($time / 86400);
$time = ($time % 86400);
$t = $value["days"] . '天前';
} elseif (86400 > $time && $time >= 3600) {
$value["hours"] = floor($time / 3600);
$time = ($time % 3600);
$t = $value["hours"] . '小时前';
} elseif (3600 > $time && $time >= 60) {
$value["minutes"] = floor($time / 60);
$time = ($time % 60);
$t = $value["minutes"] . '分钟前';
} else {
$t = $time . '秒前';
}
return $t;
} else {
return date('Y-m-d H:i:s', time());
}
}
二.前台模板调用
 
{:ChangeTime($vo.download_time)}
三.显示效果如下
 

QQ截图20190408154052.png

 

0 个评论

要回复文章请先登录注册