PHP確定當前月份中的天數

來源:互聯網
上載者:User

標籤:ok書屋 pdf電子書下載

確定當前月份中的天數

為確定當前月份中的天數,可以使用date() 的t參數,考慮如下代碼:

printf("There are %d days in %s.", date("t") , date("F"));

如果在4月執行,則輸出如下結果:

There are 30 days in April.


確定任意給定月份的天數

有時可能希望確定某個月份的天數,而不是當前月份。只用date() 函數無法實現這一要求,因為

它需要一個時間戳記,而現在只有年份和月份。但是, mktime() 函數可以用來產生所需的結果。假設希

望確定2007年2月的天數:

$lastday = mktime(o, 0, 0, 3, 0, 2007);printf( "There are %d days in February 2007." , date( "t$lastday)) ;

執行這段代碼得到如下輸出:

There are 28 days in February 2007.

【看書】詳細教程請參見【PHP與mysql程式設計】這本的第52頁,OK書屋(www.okpdf.com)提供電子書:點擊下載  

650) this.width=650;" src="http://www.okpdf.com/attachment/1407/thread/3_1_f0f2fd7ffe57c75.png" width="384" height="516" alt="3_1_f0f2fd7ffe57c75.png" />



聯繫我們

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