php 文章多少分钟前发布函数

/*
*function:显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前
*timeInt:unix time时间戳
*format:时间显示格式
*/
function timeFormat($timeInt,$format='Y-m-d H:i:s'){
    if(empty($timeInt)||!is_numeric($timeInt)||!$timeInt){
        return '';
    }
    $d=time()-$timeInt;
    if($d<0){
        return '';
    }else{
        if($d<60){
            return $d.'秒前';
        }else{
            if($d<3600){
                return floor($d/60).'分钟前';
            }else{
                if($d<86400){
                    return floor($d/3600).'小时前';
                }else{
                    if($d<2592000){//30天内
                        return floor($d/86400).'天前';
                    }else{
                        return date($format,$timeInt);
                    }
                }
            }
        }
    }
}

posted @ 2015-04-09 10:15  niub  阅读(247)  评论(0编辑  收藏  举报