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; }