/** Friendly time display * * @param int $sTime time to display * @param string $type type. Normal | mohu | full | ymd | ot Her * @param string $alt expired * @return string*/ functionFriendlydate ($sTime,$type= ' normal ',$alt= ' false ') { if(!$sTime) return‘‘; //stime= source time, ctime= current time, dtime= difference $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 seconds ago, n minutes ago, n hours ago, date if($type= = ' normal '){ if($dTime< 60 ){ if($dTime< 10){ return' Just ';//by Yangjs}Else{ return intval( Floor($dTime/10) * 10). " Seconds Ago "; } }ElseIf($dTime< 3600 ){ return intval($dTime/60). " Minutes Ago "; //today's data. Same year. Same date .}ElseIf($dYear==0 &&$dDay= = 0 ){ //return Intval ($dTime/3600). " Hours ago "; return' Today '.Date(' H:i ',$sTime); }ElseIf($dYear==0){ return Date("M-month D-Day h:i",$sTime); }Else{ return Date("Y-m-d h:i",$sTime); } }ElseIf($type= = ' Mohu '){ if($dTime< 60 ){ return $dTime." Seconds Ago "; }ElseIf($dTime< 3600 ){ return intval($dTime/60). " Minutes Ago "; }ElseIf($dTime>= 3600 &&$dDay= = 0 ){ return intval($dTime/3600). " Hours ago "; }ElseIf($dDay> 0 &&$dDay<=7 ){ return intval($dDay)." Days Ago "; }ElseIf($dDay> 7 &&$dDay<= 30 ){ return intval($dDay/7). ' Weeks ago '; }ElseIf($dDay> 30 ){ return intval($dDay/30). ' A month ago '; } //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." Seconds Ago "; }ElseIf($dTime< 3600 ){ return intval($dTime/60). " Minutes Ago "; }ElseIf($dTime>= 3600 &&$dDay= = 0 ){ return intval($dTime/3600). " Hours ago "; }ElseIf($dYear==0){ return Date("Y-m-d h:i:s",$sTime); }Else{ return Date("Y-m-d h:i:s",$sTime); } } }
PHP shows a few days ago time function