PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > PHP教程 > 正文

    php获取时间几秒前、几分钟前、几小时前、几天前....

    作者:admin来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:php获取时间几秒前、几分钟前、几小时前、几天前...
    1. /** 
    2. *   短时间显示, 几分钟前,几秒前... 
    3. **/ 
    4.  
    5.  
    6. function _put_time($time = 0,$test=''){ 
    7.     if(emptyempty($time)){return $test;} 
    8.     $time = substr($time,0,10); 
    9.     $ttime = time() - $time
    10.     if($ttime <= 0 || $ttime < 60){ 
    11.         return '几秒前'
    12.     }    
    13.     if($ttime > 60 && $ttime <120){ 
    14.         return '1分钟前'
    15.     } 
    16.      
    17.     $i = floor($ttime / 60);                            //分 
    18.     $h = floor($ttime / 60 / 60);                       //时 
    19.     $d = floor($ttime / 86400);                         //天 
    20.     $m = floor($ttime / 2592000);                       //月 
    21.     $y = floor($ttime / 60 / 60 / 24 / 365);            //年 
    22.     if($i < 30){ 
    23.         return $i.'分钟前'
    24.     } 
    25.     if($i > 30 && $i < 60){ 
    26.         return '一小时内'
    27.     } 
    28.     if($h>=1 && $h < 24){ 
    29.         return $h.'小时前'
    30.     } 
    31.     if($d>=1 && $d < 30){ 
    32.         return $d.'天前'
    33.     }    
    34.     if($m>=1 && $m < 12){        
    35.         return $m.'个月前'
    36.     } 
    37.     if($y){ 
    38.         return $y.'年前'
    39.     }    
    40.     return ""
    41.      

     

    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-10-2851-1.html
    相关热词搜索: