Carbon 可以返回给定年份的天数吗?
$dt = Carbon::parse($year . '-'. 1 .'-' . $from);
var_dump($dt->format('z') + 1 );
这似乎不起作用
echo 'Days in the year: ', 365 + $dt->format('L');
:是否是闰年;L
如果是闰年,1
否则0
使用碳属性可以获得
Carbon::parse('2020-01')->daysInYear //for year
Carbon::parse('2020-01')->daysInMonth //for month
您可以通过使用比较
来做到这一点echo 'Days in the year: ', ($dt->isLeapYear() ? 366 : 365);