人性化评论时间

人性化评论时间

Laoyao
2020-07-26 / 0 评论 / 1,282 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年12月23日,已超过860天没有更新,若内容或图片失效,请留言反馈。

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

<?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;
            $name = $chunks$i;
        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);?>
2

评论

博主关闭了当前页面的评论