zoukankan      html  css  js  c++  java
  • php 显示某一个时间相当于当前时间在多少秒前,多少分钟前,多少小时前

        /* 
            *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); 
                                } 
                            } 
                        } 
                    } 
                } 
            } 
    

      

  • 相关阅读:
    梯度消失和梯度爆炸
    BN的作用与使用过程
    百面机器学习笔记(二)
    正则表达式
    CSS Sprite
    事件绑定
    拖拽
    oncontextmenu
    鼠标跟随
    鼠标事件
  • 原文地址:https://www.cnblogs.com/xiaoyueer/p/4349166.html
Copyright © 2011-2022 走看看