我试图迭代从first day of this month到的日期last day of April:
$month_start = new DateTime("first day of this month");
$month_end = new DateTime("last day of April");
while ($month_start <= $month_end) {
echo $month_start->format("Y-m-d\n");
$month_start->add(new DateInterval('P1D'));
}
截至2020 年3 月 22 日的输出(演示):
2020-03-01
2020-03-02
2020-03-03
...
2020-04-27
2020-04-28
2020-04-29
如您所见,尽管<=在比较中使用了 ,但输出中缺少 4 月 30 日。这是为什么?
慕的地8271018