1

在 Laravel 应用程序中,我有像 01、02、03 到 12 这样的月份编号。我想得到这个月的所有天数。我不能使用daysInMonth()因为我没有日期,我只有月数。

Carbon::now()->daysInMonth();

我怎么能做这个?

4

2 回答 2

4

你可以这样做

Carbon::now()->month($month_number)->daysInMonth;

// ...

Carbon::now()->month(02)->daysInMonth; // 28
于 2021-10-12T20:52:27.407 回答
0

你也可以这样做

Carbon::createFromDate(null, $number_of_month, 1)->daysInMonth;
于 2022-01-31T23:12:20.840 回答