php获取一个月对应的所有日期天数

php获取一个月对应的所有日期天数
<?php
//获取一个月的天数
public function getAllDatesOfMonth($year, $month) {
  1. $dates = [];
  2. $firstDayOfMonth = new\DateTime("{$year}-{$month}-01");
  3. $lastDayOfMonth = new\DateTime("{$year}-{$month}-01");
  4. $lastDayOfMonth->modify('last day of this month');
  5. $interval = new\DateInterval('P1D');
  6. $dateRange = new\DatePeriod($firstDayOfMonth, $interval, $lastDayOfMonth);
  7. foreach ($dateRange as $date) {
  8. $dates[] = $date->format('Y-m-d');
  9. }
  10. return$dates;
}
?>
    A+
发布日期:2024年06月10日  所属分类:php

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: