1.根据指定日期获取月份日期
// 获取当月日期
// $date=20200107
$now = Carbon::parse($date);
$firstDay = $now->firstOfMonth()->format('Ymd');
// 20200101
$lastDay = $now->lastOfMonth()->format('Ymd');
// 20200131
- 获取当月日期
$now = Carbon::now();
// // 2020-03-14 15:18:34
$firstDay = $now->firstOfMonth()->format('Ymd');
// 20200301
$lastDay = $now->lastOfMonth()->format('Ymd');
// 20200331
其他函数
$now->toDateString(); //2020-03-14
$now->toDateTimeString(); //2020-03-14 20:22:50
Carbon::parse('2016-10-15')->toDateTimeString(); //2016-10-15 00:00:00