美文网首页
php处理显示几天前,几小时前,几分钟前

php处理显示几天前,几小时前,几分钟前

作者: 张浩宇_ | 来源:发表于2020-06-27 19:30 被阅读0次

function dayfast($the_time = null){

        $now_time = date("Y-m-d H:i:s", time() );

        $now_time = strtotime($now_time);

        if (is_numeric($the_time)){

            $show_time = $the_time;

            // 待定验证字符串日期

        }else{

            $show_time = strtotime($the_time);

        }

        $dur = $now_time - $show_time;

        if ($dur < 0) {

            return $the_time;

        } else {

            if ($dur < 60) {

                return $dur . '秒前';

            } else {

                if ($dur < 3600) {

                    return floor($dur / 60) . '分钟前';

                } else {

                    if ($dur < 86400) {

                        return floor($dur / 3600) . '小时前';

                    } else {

                        if ($dur < 259200) {//3天内

                            return floor($dur / 86400) . '天前';

                        } else {

                            $the_time = date("Y-m-d",$show_time);

                            return $the_time;

                        }

                    }

                }

            }

        }

    }

相关文章

网友评论

      本文标题:php处理显示几天前,几小时前,几分钟前

      本文链接:https://www.haomeiwen.com/subject/emjvfktx.html