PHP通用函數,php通用
1 /** 2 * 時間軸函數, Unix 時間戳記 3 * @param int $time 時間 4 */ 5 function TranTime($time) { 6 //$time = strtotime($time); 7 $nowTime = time (); 8 $message = ''; 9 //一年前10 if (idate ( 'Y', $nowTime ) != idate ( 'Y', $time )) {11 $message = date ( 'Y年m月d日', $time );12 }13 else {14 //同一年15 $days = idate ( 'z', $nowTime ) - idate ( 'z', $time );16 switch(true){17 //一天內18 case (0 == $days):19 $seconds = $nowTime - $time;20 //一小時內21 if ($seconds < 3600) {22 //一分鐘內23 if ($seconds < 60) {24 if (3 > $seconds) {25 $message = '剛剛';26 } else {27 $message = $seconds . '秒前';28 }29 }30 $message = intval ( $seconds / 60 ) . '分鐘前';31 }32 $message = idate ( 'H', $nowTime ) - idate ( 'H', $time ) . '小時前';33 break;34 //昨天35 case (1 == $days):36 $message = '昨天' . date ( 'H:i', $time );37 break;38 //前天39 case (2 == $days):40 $message = '前天 ' . date ( 'H:i', $time );41 break;42 //7天內43 case (7 > $days):44 $message = $days . '天前';45 break;46 //超過7天47 default:48 $message = date ( 'n月j日 H:i', $time );49 break;50 }51 }52 return $message;53 }
http://www.bkjia.com/PHPjc/969883.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/969883.htmlTechArticlePHP通用函數,php通用 1 /* * 2 * 時間軸函數, Unix 時間戳記 3 * @param int $time 時間 4 */ 5 function TranTime( $time ) { 6 // $time = strtotime($time); 7 $nowTime = t...