时间美化函数1.0
public function format_date($time)
{
$t = time() - $time;
$f = array(
'31536000' => '年',
'2592000' => '个月',
'604800' => '星期',
'86400' => '天',
'3600' => '小时',
'60' => '分钟',
'1' => '秒'
);
foreach ($f as $k => $v) {
if (0 != $c = floor( $t / (int)$k )) {
return $c.$v.'前';
}
}
}
时间美化函数2.0
public function format_time($time)
{
$todayLast = strtotime(date('Y-m-d').' 23:59:59');
$agoTimeTrue = time() - $time;
$agoTime = $todayLast - $time;
$agoDay = floor($agoTime / 86400);
$res = '';
if ($agoTimeTrue < 60) {
$res = '刚刚';
}elseif ($agoTimeTrue < 3600) {
$res = (ceil($agoTimeTrue / 60)).'分钟前';
}elseif ($agoTimeTrue < (3600 * 12)) {
$res = (ceil($agoTimeTrue / 3600)).'小时前';
}elseif ($agoDay == 0) {
$res = '今天 '.date('H:i',$time);
}elseif ($agoDay == 1) {
$res = '昨天 '.date('H:i',$time);
}elseif ($agoDay == 2) {
$res = '前天 '.date('H:i',$time);
}elseif (($agoDay > 2) && ($agoDay < 16)) {
$res = $agoDay.'天前'.date('H:i',$time);
}else{
$res = date('Y-m-d H:i:s',$time);
}
return $res;
}
$time