PHP Disposition date format is seconds ago, minutes ago, hours ago, yesterday, the day before

Source: Internet
Author: User
PHP processing date format is seconds ago, minutes ago, hours ago, yesterday, the day before
    /** * Change the date format to a different display style according to the following rules * Less than 1 minutes show how many seconds ago * less than 1 hours, show how many minutes ago * day, show how many hours ago * 3 days, show the day before yesterday 22:23 or yesterday: 12:23.     * More than 3 days, the full date is displayed. * @static * @param $sorce _date data Source Date Unix timestamp * @return void */public static function Getdatestyle ($sorce _  Date) {self:: $nowTime = time (); Get today timestamp//echo ' data source timestamp: '. $sorce _date. ' = '. Date (' y-m-d h:i:s ', $sorce _date);//echo "\ n Current timestamp:". Date (' y-m-d h:i:s ', Self:: $nowTime). "        \ n "; $timeHtml = ";        Returns the text format $temp _time = 0; Switch ($sorce _date) {//one-minute case ($sorce _date+60) >=self:: $nowTime: $temp _time = sel                F:: $nowTime-$sorce _date; $timeHtml = $temp _time. "                Seconds ago ";            Break Hour case ($sorce _date+3600) >=self:: $nowTime: $temp _time = Date (' I ', Self:: $nowTime-$sorce _dat                e); $timeHtml = $temp _time. "                Minutes ago ";            Break Day case ($sorce _date+3600*24) >=self:: $nowTime: $temp _time = date (' h ', Self:: $nowTime)-date (' H ', $sorce _date); $timeHtml = $temp _time. '                Hours ago ';            Break                Yesterday case ($sorce _date+3600*24*2) >=self:: $nowTime: $temp _time = Date (' h:i ', $sorce _date);                $timeHtml = ' Yesterday '. $temp _time;            Break                The day before yesterday case ($sorce _date+3600*24*3) >=self:: $nowTime: $temp _time = Date (' h:i ', $sorce _date);                $timeHtml = ' The day before yesterday '. $temp _time;            Break                3 days ago Case ($sorce _date+3600*24*4) >=self:: $nowTime: $timeHtml = ' 3 days ago ';            Break                Default: $timeHtml = Date (' y-m-d ', $sorce _date);        Break    } return $timeHtml; }
  • Related Article

    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.