码迷,mamicode.com
首页 > Web开发 > 详细

php自定义函数: 时间转换成智能形式

时间:2018-01-02 11:40:52      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:自定义函数   post   ret   定义函数   智能   php   body   时间转换   atime   

function time_trans($paratime,$suffix=false){
    $now_time = time();
    $dur = $now_time - $paratime;
    $suffix && $sustr = ‘前‘;
    if($dur < 0){
        return $time;
    }else{
        if($dur < 60){
            return $dur.‘秒‘.$sustr;
        }else{
            if($dur < 3600){
                return floor($dur/60).‘分钟‘.$sustr;
            }else{
                if($dur < 86400){
                    return floor($dur/3600).‘小时‘.$sustr;
                }else{
                    if($dur < 259200){//3天内
                        return floor($dur/86400).‘天‘.$sustr;
                    }else{
                        return $time;
                    }
                }
            }
        }
    }
}

  

php自定义函数: 时间转换成智能形式

标签:自定义函数   post   ret   定义函数   智能   php   body   时间转换   atime   

原文地址:https://www.cnblogs.com/upup2015/p/8175675.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!