给定年份的碳返还天数

问题描述 投票:0回答:3

Carbon 可以返回给定年份的天数吗?

    $dt = Carbon::parse($year . '-'. 1 .'-' . $from);

    var_dump($dt->format('z') + 1 );

这似乎不起作用

php date php-carbon
3个回答
5
投票
echo 'Days in the year: ', 365 + $dt->format('L');

L
:是否是闰年;
1
如果是闰年,
0
否则


2
投票

使用碳属性可以获得

Carbon::parse('2020-01')->daysInYear //for year

Carbon::parse('2020-01')->daysInMonth //for month

1
投票

您可以通过使用比较

来做到这一点
echo 'Days in the year: ', ($dt->isLeapYear() ? 366 : 365);
© www.soinside.com 2019 - 2024. All rights reserved.