Php計算時間差 php日期轉換的例子

來源:互聯網
上載者:User

實現一個計算時間差的代碼,統計出了天數,記得曾經在別的程式裡看到過換算成年月日的,於是著手寫了一下,其實很簡單,就是幾個換算,但在月統計上不是很準確,因為換成月,不知道是按多少天算,所以我換成月30天換算的,誤差應該不大,這個是無法解決的。

例子,計算建站時間的代碼:$jztime 建站時間 格式:2013-01-01

  1. $days = abs(strtotime($jztime) - strtotime(date("Y-m-d")))/86400;
  2. if ($days>365){
  3. $site_Y=intval($days/365)."年-";
  4. }
  5. if ($days>31){
  6. $str=explode(".",$days/365);//取得年餘下的資料
  7. $site_m = ("0.".$str[(count($str)-1)])*365/30;
  8. $site_m = intval($site_m)."月-";
  9. } bbs.it-home.org
  10. if ($days>1){
  11. $str=explode(".",$days/365);//繼續取得餘下的資料
  12. $site_d = ("0.".$str[(count($str)-1)])*365-(intval($site_m)*30);
  13. $site_d = intval($site_d)."天";
  14. }
  15. $dayst= $site_Y.$site_m.$site_d;
  16. echo $dayst;
  17. ?>
複製代碼
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.