php时间轴函数,时间戳转换为刚刚,三秒前,5分钟前等
Posted 北方的刀郎
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php时间轴函数,时间戳转换为刚刚,三秒前,5分钟前等相关的知识,希望对你有一定的参考价值。
public function TranTime($time)
//$time = strtotime($time);
$nowTime = time();
$message = '';
if(empty($time))
$message='很早以前';
return $message;
//一年前
$year = idate ( 'Y', $nowTime ) - idate ( 'Y', $time );
if ($year>0)
if($year==1)
$message = "1年前";
else
$message = date ( 'Y.m.d', $time );
else
//同一年
$days = idate ( 'z', $nowTime ) - idate ( 'z', $time );
switch(true)
//一天内
case (0 == $days):
$seconds = $nowTime - $time;
//一小时内
if ($seconds < 3600)
//一分钟内
if ($seconds < 60)
$message = '刚刚';
else
$message = intval ( $seconds / 60 ) . '分钟前';
else
$message = idate ( 'H', $nowTime ) - idate ( 'H', $time ) . '小时前';
break;
//昨天
case (1 == $days):
$message = '昨天' . date ( 'H:i', $time );
break;
//前天
case (2 == $days):
$message = '前天 ' . date ( 'H:i', $time );
break;
//7天内
case (7 > $days):
$message = $days . '天前';
break;
case (60 > $days):
$message = '1月前';
break;
case (120 > $days):
$message = '3月前';
break;
case (360 > $days):
$message = '半年前';
break;
default:
$message = date ( 'n月j日 H:i', $time );
break;
return $message;
以上是关于php时间轴函数,时间戳转换为刚刚,三秒前,5分钟前等的主要内容,如果未能解决你的问题,请参考以下文章