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

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); 

 

 

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注