: This article describes how to obtain the number of days of the month in php. For more information about PHP tutorials, see. At work, I often encounter the problem of getting the number of days in a month. I previously solved this problem.
// This example uses June 1 as an example. $ inputs ['month'] = '20160301'; // The passed parameter $ tmp_month = $ inputs ['month']. "01"; // $ tmp_month = '20140901'; $ s_time = strtotime ($ tmp_month); // month start time $ e_time = strtotime (date ("Ymd ", $ s_time ). '+ 1 month'); // The end time of the month $ countMins = ($ e_time-$ s_time)/60; // The number of minutes in the current month $ countDay = $ countMins/(60*24); // The number of days in the current month
But now, we have found a better way to get it.
Php built-in function date (), you can directly obtain the number of days of the month.
$ Tmp_month = $ inputs ['month']. "01"; $ countDay = date ("t", strtotime ($ tmp_month); // If date ("t") is used directly, the number of days in the current month is obtained.
So easy!
In fact, there is another way to use the cal_days_in_month () function. The php Manual explains: return the number of days of a month in a calendar.
Three parameters:
Calendar used for computing
Month indicates a month in the selected calendar.
Year indicates the year in the selected calendar.
$num = cal_days_in_month(CAL_GREGORIAN, 11, 2015); // 30
I personally prefer the date () function, so I don't need to consider calendar issues.
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The preceding section describes how to obtain the number of days of a specified date in php, including the number of days of the current month. I hope to help anyone who is interested in the PHP Tutorial.