php根据年月获取月初月末时间
$months = '2022-06';
$time1 = date('Y-m-01 00:00:00', strtotime($months));
$time2 = date('Y-m-d 23:59:59', strtotime("$time1 +1 month -1 day"));
print_r(['time1'=>$time1, 'time2'=>$time2]);
- 打印结果
Array
(
[time1] => 2022-06-01 00:00:00
[time2] => 2022-06-30 23:59:59
)