https://blog.csdn.net/qq_36025814/article/details/108093835
public function test() {
//当前月份(2020-08)上一个月最后一天
$lastMonthLastDay = date("Y-m-d", strtotime("last day of -1 month"));
echo $lastMonthLastDay . ''; //打印:2020-07-31
//指定月份的第一天
$month = '2020-04';
$lastMonthLastDay = date("Y-m-d", strtotime("first day of {$month}"));
echo $lastMonthLastDay . ''; //打印:2020-04-01
//指定月份的最后一天
$month = '2020-01';
$lastMonthLastDay = date("Y-m-d", strtotime("{$month} +1 month -1 day"));
echo $lastMonthLastDay . ''; //打印:2020-01-31
//指定月份的上一个月的第一天
$month = '2020-03';
$lastMonthLastDay = date("Y-m-d", strtotime("{$month} first day of -1 month"));
echo $lastMonthLastDay . ''; //打印:2020-02-01
//指定月份的上一个月的最后一天
$month = '2020-04';
$lastMonthLastDay = date("Y-m-d", strtotime("{$month} last day of -1 month"));
echo $lastMonthLastDay . ''; //打印:2020-03-31
//指定月份的下一个月的第一天
$month = '2020-03';
$lastMonthLastDay = date("Y-m-d", strtotime("{$month} first day of +1 month"));
echo $lastMonthLastDay . ''; //打印:2020-04-01
//指定月份的下一个月的最后一天
$month = '2020-04';
$lastMonthLastDay = date("Y-m-d", strtotime("{$month} last day of +1 month"));
echo $lastMonthLastDay; //打印:2020-05-31
}