php 时间戳转换 刚刚,分钟前,小时前 ,昨天和时间

 1 function unixTime($time)
 2 {
 3    //获取今天凌晨的时间戳
 4    $day = strtotime(date('Y-m-d',time()));
 5    //获取昨天凌晨的时间戳
 6    $pday = strtotime(date('Y-m-d',strtotime('-1 day')));
 7    //获取现在的时间戳
 8    $nowtime = time();   
 9    $t = $nowtime-$time;
10    if($time<$pday){
11       $str = date('Y-m-d H:i:s',$time);
12    }elseif($time<$day && $time>$pday){
13       $str = "昨天";
14    }elseif($t>60*60){
15       $str = floor($t/(60*60))."小时前";
16    }elseif($t>60){
17       $str = floor($t/60)."分钟前";
18    }else{
19       $str = "刚刚";
20    }
21    return $str;
22 }

猜你喜欢

转载自www.cnblogs.com/cnn2017/p/9989959.html