0712-2888027 189-8648-0214
微信公众号

孝感风信网络科技有限公司微信公众号

当前位置:主页 > 技术支持 > PHP > php根据当前用户信息时间显示时间状态的代码片段

php根据当前用户信息时间显示时间状态的代码片段

时间:2024-10-02来源:风信官网 点击: 704次
php根据当前用户信息时间显示时间状态的代码片段,以下代码为项目开发中的片段,实现方法思路仅供参考。
<?php

$created_at = !empty($v->created_at) ? $v->created_at : $v->created_at_as;
$time_differents = time() - strtotime($created_at);
$time_differents = round($time_differents/3600, 3);
//返回当前时间状态
switch ($time_differents) {
    case $time_differents <= 0.033:
        $data[$k]->visit_time = '刚刚';
        break;
    
    case $time_differents <= 0.033 && $time_differents < 1:
        $data[$k]->visit_time = round($time_differents*60, 0).'分钟前';
        break;

    case $time_differents <= 1 && $time_differents < 24:
        $data[$k]->visit_time = round($time_differents).'小时前';
        break;

    case $time_differents <= 24 && $time_differents < 48:
        $data[$k]->visit_time = '昨天';
        break;

    case $time_differents <= 48 && $time_differents < 72:
        $data[$k]->visit_time = '2天前';
        break;

    case $time_differents <= 72 && $time_differents < 96:
        $data[$k]->visit_time = '3天前';
        break;

    case $time_differents <= 96 && $time_differents < 120:
        $data[$k]->visit_time = '4天前';
        break;

    case $time_differents <= 120 && $time_differents < 144:
        $data[$k]->visit_time = '5天前';
        break;

    case $time_differents <= 144 && $time_differents < 168:
        $data[$k]->visit_time = '6天前';
        break;

    case $time_differents <= 168 && $time_differents < 336:
        $data[$k]->visit_time = '1周前';
        break;

    default:
        # code...
        break;
}
栏目列表
推荐内容
热点内容
展开