• 有好时间显示


      
        function friendlyDate($sTime,$type = 'normal',$alt = 'false') {
            if (!$sTime)
                return '';
            //sTime=源时间,cTime=当前时间,dTime=时间差
            $cTime      =   time();
            $dTime      =   $cTime - $sTime;
            $dDay       =   intval(date("z",$cTime)) - intval(date("z",$sTime));
            //$dDay     =   intval($dTime/3600/24);
            $dYear      =   intval(date("Y",$cTime)) - intval(date("Y",$sTime));
            //normal:n秒前,n分钟前,n小时前,日期
            if($type=='normal'){
                if( $dTime < 60 ){
                    if($dTime < 10){
                        return '刚刚';    //by yangjs
                    }else{
                        return intval(floor($dTime / 10) * 10)."秒前";
                    }
                }elseif( $dTime < 3600 ){
                    return intval($dTime/60)."分钟前";
                    //今天的数据.年份相同.日期相同.
                }elseif( $dYear==0 && $dDay == 0  ){
                    //return intval($dTime/3600)."小时前";
                    return '今天'.date('H:i',$sTime);
                }elseif($dYear==0){
                    return date("m月d日 H:i",$sTime);
                }else{
                    return date("Y-m-d H:i",$sTime);
                }
            }elseif($type=='mohu'){
                if( $dTime < 60 ){
                    return $dTime."秒前";
                }elseif( $dTime < 3600 ){
                    return intval($dTime/60)."分钟前";
                }elseif( $dTime >= 3600 && $dDay == 0  ){
                    return intval($dTime/3600)."小时前";
                }elseif( $dDay > 0 && $dDay<=7 ){
                    return intval($dDay)."天前";
                }elseif( $dDay > 7 &&  $dDay <= 30 ){
                    return intval($dDay/7) . '周前';
                }elseif( $dDay > 30 ){
                    return intval($dDay/30) . '个月前';
                }
                //full: Y-m-d , H:i:s
            }elseif($type=='full'){
                return date("Y-m-d , H:i:s",$sTime);
            }elseif($type=='ymd'){
                return date("Y-m-d",$sTime);
            }else{
                if( $dTime < 60 ){
                    return $dTime."秒前";
                }elseif( $dTime < 3600 ){
                    return intval($dTime/60)."分钟前";
                }elseif( $dTime >= 3600 && $dDay == 0  ){
                    return intval($dTime/3600)."小时前";
                }elseif($dYear==0){
                    return date("Y-m-d H:i:s",$sTime);
                }else{
                    return date("Y-m-d H:i:s",$sTime);
                }
            }
        }
     
  • 相关阅读:
    Java并发编程有多难?这几个核心技术你掌握了吗?
    「mysql优化专题」主从复制面试宝典!面试官都没你懂得多!(11)
    「mysql优化专题」高可用性、负载均衡的mysql集群解决方案(12)
    「mysql优化专题」什么是慢查询?如何通过慢查询日志优化?(10)
    「mysql优化专题」详解引擎(InnoDB,MyISAM)的内存优化攻略?(9)
    vsftp虚拟用户配置
    Oracle shrink space
    linux加程序是否当掉检测脚本
    oracke创建db link
    Oracle函数日期转换成秒(时间戳)
  • 原文地址:https://www.cnblogs.com/xiaocaiabc/p/5286849.html
Copyright © 2020-2023  润新知