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
)
posted @ 2022-06-22 10:05  pine007  阅读(366)  评论(0编辑  收藏  举报