1. 程式人生 > >格式化友好時間格式

格式化友好時間格式

友好 tle turn cti 一個 int ret mda func

<td height="40" title="<{$rs.regtime|date=‘Y-m-d H:i:s‘,###}>"><{$rs.regtime|mdate}></td>



/**
* 格式化友好時間格式
* @param unknown $time
* @return string
*/
function mdate($time = NULL) {
$text = ‘‘;
$time = $time === NULL || $time > time() ? time() : intval($time);
$t = time() - $time; //時間差 (秒)
if ($t == 0)
$text = ‘剛剛‘;
elseif ($t < 60)
$text = $t . ‘秒前‘; // 一分鐘內
elseif ($t < 60 * 60)
$text = floor($t / 60) . ‘分鐘前‘; //一小時內
elseif ($t < 60 * 60 * 24)
$text = floor($t / (60 * 60)) . ‘小時前‘; // 一天內
elseif ($t < 60 * 60 * 24 * 3)
$text = floor($time/(60*60*24)) ==1 ?‘昨天 ‘ . date(‘H:i‘, $t) : ‘前天 ‘ . date(‘H:i‘, $time) ; //昨天和前天
elseif ($t < 60 * 60 * 24 * 30)
$text = date(‘m月d日 H:i‘, $time); //一個月內
elseif ($t < 60 * 60 * 24 * 365)
$text = date(‘m月d日‘, $time); //一年內
else
$text = date(‘Y年m月d日‘, $time); //一年以前
return $text;
}

格式化友好時間格式