php获取一个月对应的所有日期天数
<?php//获取一个月的天数public function getAllDatesOfMonth($year, $month) {
- $dates = [];
- $firstDayOfMonth = new\DateTime("{$year}-{$month}-01");
- $lastDayOfMonth = new\DateTime("{$year}-{$month}-01");
- $lastDayOfMonth->modify('last day of this month');
- $interval = new\DateInterval('P1D');
- $dateRange = new\DatePeriod($firstDayOfMonth, $interval, $lastDayOfMonth);
- foreach ($dateRange as $date) {
- $dates[] = $date->format('Y-m-d');
- }
- return$dates;
}?>