生成時間狀態

public function timeStatus($data)
{
foreach ($data as $k => $v)
{

$created_at = !empty($v->created_at) ? $v -> created_at : $v -> created_at_ask;
$time_differents = time()-strtotime($created_at);
$time_differents = round($time_differents/3600,3);
//返回當前時間狀態
switch ($time_differents)
{
case $time_differents<=0.033:
$data[$k] -> visit_time = '剛剛';
break;
case $time_differents>0.033&&$time_differents<1:
$data[$k] -> visit_time = round($time_differents*60,0).'分鐘前';
break;
case $time_differents>=1&&$time_differents<24:
$data[$k] -> visit_time = round($time_differents).'小時前';
break;
case$time_differents>=24&&$time_differents<48:
$data[$k] -> visit_time = '昨天';
break;
case $time_differents>=48&&$time_differents<72:
$data[$k] -> visit_time = '2天前';
break;
case $time_differents>=72&&$time_differents<96:
$data[$k] -> visit_time = '3天前';
break;
case $time_differents>=96&&$time_differents<120:             $data[$k] -> visit_time = '4天前';             break;          case $time_differents>=120&&$time_differents<144:             $data[$k] -> visit_time = '5天前';             break;          case $time_differents>=144&&$time_differents<168:             $data[$k] -> visit_time = '6天前';             break;          case $time_differents>=168&&$time_differents<192:             $data[$k] -> visit_time = '7天前';             break;          case $time_differents>192:           if(date('Y',strtotime($v->created_at)) != date('Y',time()))           {             $data[$k] -> visit_time = date('Y-m-d',strtotime($created_at)); }else           {             $data[$k] -> visit_time = date('m月d日',strtotime($created_at));           }             break;         default:             $data[$k] -> visit_time = '剛剛';          }       }       return $data;  }
相關文章
相關標籤/搜索