Within a minute "Just now" Within an hour "* minutes ago" Within today "Today's hour: minutes" Within yesterday "Yesterday's hour: minutes "Greater than 2 days" Year-month-day hour: minutes"
- / /Format time
- function format_date($beforetime)
- {
- $time= time() - $beforetime;
- $today=strtotime(date("M-d-y",mktime(0,0,0,date("m") ,date("d"),date("Y"))));
- if($time <= 60){
- return 'just';
- }elseif($time>=60 && $time<3600) {
- $return=intval($time / 60)." minutes ago";
- }else{
- if($beforetime>$today){
- $return="Today".date("H:i",$beforetime );
- }elseif($beforetime<$today && $beforetime>($today-86400)){
- $return="Yesterday".date("H:i",$beforetime);
- }else{
- $return =date("Y-m-d H:i",$beforetime);
- }
- }
- return $return;
- }
Copy code
|