PHP shows a few days ago time function

Source: Internet
Author: User

    /** 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.