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

  function unixTime($time)
  {
     //获取今天凌晨的时间戳
     $day = strtotime(date('Y-m-d',time()));
     //获取昨天凌晨的时间戳
     $pday = strtotime(date('Y-m-d',strtotime('-1 day')));
     //获取现在的时间戳
     $nowtime = time();   
     $t = $nowtime-$time;
    if($time<$pday){
       $str = date('Y-m-d H:i:s',$time);
    }elseif($time<$day && $time>$pday){
       $str = "昨天";
    }elseif($t>60*60){
       $str = floor($t/(60*60))."小时前";
    }elseif($t>60){
       $str = floor($t/60)."分钟前";
    }else{
       $str = "刚刚";
    }
    return $str;
 }

  

$now_time = time();
 $total_week = isset($_REQUEST['total_week']) && ($_REQUEST['total_week']>0) ? $_REQUEST['total_week'] : 1;
$begin = $now_time - $total_week * 7 * 86400;
$statDate = date("Y/m/d", $begin);
$end = $now_time -($total_week - 1) * 7 * 86400;
$endDate = date("Y/m/d", $end);

  

posted @ 2018-11-20 16:56  calmly  阅读(548)  评论(0编辑  收藏  举报