<?php
$cur = '2020-01-01';
function getNextMonthCurDayOrLastDay($date) {
// 先判断下个月有没有当前月份的今天,有的话下个月取今天,没有的话下个月取最后一天
$curDay = date('d', strtotime($date));
$lastDayOfNextMonth = date('d', strtotime("last day of next month", strtotime($date)));
if ($curDay <= $lastDayOfNextMonth) {
$retDate = date('Y-m-d', strtotime("+1 month", strtotime(($date))));
} else {
$retDate = date('Y-m-d', strtotime("last day of next month", strtotime($date)));
}
return $retDate;
}
// echo getNextMonthCurDayOrLastDay('2020-01-28');
// 测试一年的数据
for ($i = 0; $i < 366; $i++) {
echo getNextMonthCurDayOrLastDay($cur).PHP_EOL;
$cur = date('Y-m-d', strtotime("+1 day", strtotime($cur)));
}
版权声明:本文为kikajack原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。