/*
*
* friendlyDate()
*
* @param mixed $sTime
* @param string $type,当full时,返回全部时间日期
* @return 友好的时间日期
*/
function friendlyDate( $sTime , $type = ' normal ' ) {
// sTime=源时间,cTime=当前时间,dTime=时间差
$cTime = time ();
$dTime = $cTime - $sTime ;
$dDay = intval ( date ( " Ymd " , $cTime )) - intval ( date ( " Ymd " , $sTime ));
$dYear = intval ( date ( " Y " , $cTime )) - intval ( date ( " Y " , $sTime ));
// normal:n秒前,n分钟前,n小时前,日期
if ( $type == ' normal ' ){
if ( $dTime < 60 ){
echo $dTime . " 秒前 " ;
} elseif ( $dTime < 3600 ){
echo intval ( $dTime / 60 ) . " 分钟前 " ;
} elseif ( $dTime >= 3600 && $dDay == 0 ){
echo intval ( $dTime / 3600 ) . " 小时前 " ;
} elseif ( $dYear == 0 ){
echo date ( " m-d ,H:i " , $sTime );
} else {
echo date ( " Y-m-d ,H:i " , $sTime );
}
// full: Y-m-d , H:i:s
} elseif ( $type == ' full ' ){
echo date ( " Y-m-d , H:i:s " , $sTime );
} else {
if ( $dTime < 60 ){
return $dTime . " 秒前 " ;
} elseif ( $dTime < 3600 ){
return intval ( $dTime / 60 ) . " 分钟前 " ;
} elseif ( $dTime >= 3600 && $dDay == 0 ){
return intval ( $dTime / 3600 ) . " 小时前 " ;
} elseif ( $dYear == 0 ){
return date ( " m-d ,H:i " , $sTime );
} else {
return date ( " Y-m-d ,H:i " , $sTime );
}
}
}
* friendlyDate()
*
* @param mixed $sTime
* @param string $type,当full时,返回全部时间日期
* @return 友好的时间日期
*/
function friendlyDate( $sTime , $type = ' normal ' ) {
// sTime=源时间,cTime=当前时间,dTime=时间差
$cTime = time ();
$dTime = $cTime - $sTime ;
$dDay = intval ( date ( " Ymd " , $cTime )) - intval ( date ( " Ymd " , $sTime ));
$dYear = intval ( date ( " Y " , $cTime )) - intval ( date ( " Y " , $sTime ));
// normal:n秒前,n分钟前,n小时前,日期
if ( $type == ' normal ' ){
if ( $dTime < 60 ){
echo $dTime . " 秒前 " ;
} elseif ( $dTime < 3600 ){
echo intval ( $dTime / 60 ) . " 分钟前 " ;
} elseif ( $dTime >= 3600 && $dDay == 0 ){
echo intval ( $dTime / 3600 ) . " 小时前 " ;
} elseif ( $dYear == 0 ){
echo date ( " m-d ,H:i " , $sTime );
} else {
echo date ( " Y-m-d ,H:i " , $sTime );
}
// full: Y-m-d , H:i:s
} elseif ( $type == ' full ' ){
echo date ( " Y-m-d , H:i:s " , $sTime );
} else {
if ( $dTime < 60 ){
return $dTime . " 秒前 " ;
} elseif ( $dTime < 3600 ){
return intval ( $dTime / 60 ) . " 分钟前 " ;
} elseif ( $dTime >= 3600 && $dDay == 0 ){
return intval ( $dTime / 3600 ) . " 小时前 " ;
} elseif ( $dYear == 0 ){
return date ( " m-d ,H:i " , $sTime );
} else {
return date ( " Y-m-d ,H:i " , $sTime );
}
}
}