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

php 显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前

时间:2015-03-19 00:45:23      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

    /* 
        *function:显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前 
        *timeInt:unix time时间戳 
        *format:时间显示格式 
        */ 
        public  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<259200){//3天内 
                                return floor($d/86400).‘天前‘; 
                            }else{ 
                                return date($format,$timeInt); 
                            } 
                        } 
                    } 
                } 
            } 
        } 

  

php 显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前

标签:

原文地址:http://www.cnblogs.com/xiaoyueer/p/4349166.html

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