PHP通用函數,php通用_PHP教程

來源:互聯網
上載者:User

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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.