时间优化(刚刚,几分钟前,几个小时前,几天前)

[code]function formattime($time){ $minute = date("H:i",$time); $hour = date("H:i",$time); $alltime = date("Y-m-d",$time); $time = time() - $time; if ($time < 60) { $str = '刚刚 '; } elseif ($time < 60 * 60) { $min = floor($time/60); $str = $min.'分钟前 '; } elseif ($time < 60 * 60 * 24) { $h = floor($time/(60*60)); $str = $h.'小时前 '; } elseif ($time < 60 * 60 * 24 * 10) { $d = floor($time/(60*60*24)); $str = $d.'天前'; } else { $str = $alltime; } return $str; } ?>[/code] [code]日期调用方法:formattime(strtotime('2016-05-13 20:15:32')); 时间戳调用方法:formattime(1423423423); [/code]
已邀请:

要回复问题请先登录注册