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;}?>
日期调用方法:formattime(strtotime('2016-05-13 20:15:32')); 时间戳调用方法:formattime(1423423423);
转载请注明: » 帝国cms时间优化(刚刚,几分钟前,几个小时前,几天前)