想要检索给定月份的所有日期和日期.目前这个显示当月的所有日期,但是如何在指定的月份解析?
$list=array();
for($d=1; $d<=31; $d++)
{
$time=mktime(12, 0, 0, date('m'), $d, date('Y'));
if (date('m', $time)==date('m'))
$list[]=date('Y-m-d-D', $time);
}
echo "<pre>";
print_r($list);
echo "</pre>";
Run Code Online (Sandbox Code Playgroud)
for*_*une 17
试试这个
$list=array();
$month = 12;
$year = 2014;
for($d=1; $d<=31; $d++)
{
$time=mktime(12, 0, 0, $month, $d, $year);
if (date('m', $time)==$month)
$list[]=date('Y-m-d-D', $time);
}
echo "<pre>";
print_r($list);
echo "</pre>";
Run Code Online (Sandbox Code Playgroud)
Sat*_*rma 10
试试这个
$month = "05";
$year = "2014";
$start_date = "01-".$month."-".$year;
$start_time = strtotime($start_date);
$end_time = strtotime("+1 month", $start_time);
for($i=$start_time; $i<$end_time; $i+=86400)
{
$list[] = date('Y-m-d-D', $i);
}
print_r($list);
Run Code Online (Sandbox Code Playgroud)
见演示
$days = cal_days_in_month( 0, $month, $year);
Run Code Online (Sandbox Code Playgroud)
cal_days_in_month:返回给定年份和日历的一个月中的天数。
第一个参数是“日历”:
0 或 CAL_GREGORIAN - 公历
1 或 CAL_JULIAN - 儒略历
2 或 CAL_JEWISH - 犹太历
3 或 CAL_FRENCH - 法国革命历
http://php.net/manual/en/function.cal-days-in-month.php
http://php.net/manual/en/function.cal-info.php