php 日期不全補0執行個體程式碼

來源:互聯網
上載者:User

 $time = '2010-1-11';
 
 //定義一個日間我相把把它變成2010-01-1
 
 $splitDate = explode("-",$time);
 
 //進行拆分以"-"分開
 
 $stime = mktime(0,0,0,$splitDate[1],$splitDate[2],$splitDate[0]);
 
 //再用mktime把它轉換成時間載
 
 if( intval( $splitDate[1] )<10 && substr( $splitDate[1],0,1) !='0' )
 {
  $splitDate[1] = '0'.$splitDate[1];
 }
 //對月分取一個數字判斷如果是01這種格式就不操作反之就加個0
 
 if( intval( $splitDate[2] )<10 && substr( $splitDate[2],0,1) !='0' )
 {
  $splitDate[2] = '0'.$splitDate[2];
 }
 //對日期作同樣的作了,小於10就補0
 
 /*
  函數分析:
   explode 使用一個字串分割另一個字串 array explode ( string separator, string string [, int limit] )
   <a href=/phper/21/101d7c9a91356a428c8039c03dd4500b.htm>mktime</a>  函數返回一個日期的 Unix 時間戳記。 mktime(hour,minute,second,month,day,year,is_dst)
   <a href=/phper/18/9351c693420d88336920eb2c12fca245.htm>intval</a> int intval ( mixed var [, int base])
通過使用特定的進位轉換(預設是十進位),返回變數 var 的 integer 數值。

   substr  函數返回字串的一部分 substr(string,start,length)
   
 */
 ?>

本站原創教程,轉載註明來自www.111cn.net

聯繫我們

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