Typecho主题插件站
每一个作品都值得被记录

为 Typecho 主题添加人性化评论时间 多少秒 多少天发帖代码

Typecho爱好者开发日志 • 2568次浏览 • 发布 2017-11-06 • 更新 2017-11-06
极致加速的V2Ray 助您畅享全球网络 & 搬瓦工VPS最新优惠码

评论时间显示多少秒,多少天,多少时发帖代码。

<?php
function timesince($older_date,$comment_date = false) {
$chunks = array(
array(86400 , '天'),
array(3600 , '小时'),
array(60 , '分'),
array(1 , '秒'),
);
$newer_date = time();
$since = abs($newer_date - $older_date);
if($since < 2592000){
for ($i = 0, $j = count($chunks); $i < $j; $i++){
$seconds = $chunks[$i][0];
$name = $chunks[$i][1];
if (($count = floor($since / $seconds)) != 0) break;
}
$output = $count.$name.' 前';
}else{
$output = !$comment_date ? (date('Y-m-j G:i', $older_date)) : (date('Y-m-j', $older_date));
}
return $output;
}
?>

调用代码:

<?php echo timesince($comments->created);?>

本文检索关键词:typecho
厂商投放
添加新评论 »