php格式化時間綴函式

技術小大人發表於2017-11-15
<?php
/
function:顯示某一個時間相當於當前時間在多少秒前,多少分鐘前,多少小時前
timeInt:unix time時間戳
format:時間顯示格式
*/
function timeFormat($timeInt,$format=`Y-m-d H:i:s`){
if(empty($timeInt)||!is_numeric($timeInt)||!$timeInt){
return “;
}
$d=time()-$timeInt;
if($d<0){
return “;
}else{
if($d<60){
return $d.`秒前`;
}else{
if($d<3600){
return floor($d/60).`分鐘前`;
}else{
if($d<86400){
return floor($d/3600).`小時前`;
}else{
if($d<259200){//3天內
return floor($d/86400).`天前`;
}else{
return date($format,$timeInt);
}
}
}
}
}

}


本文轉自 Lee_吉  部落格,原文連結:     http://blog.51cto.com/12173069/2048672   如需轉載請自行聯絡原作者



相關文章