Carbon diffForHumans 几个月
Carbon diffForHumans with months
我尝试在 Laravel 应用中使用 Carbon 获取 2 个日期之间的差异,即日期 now() 和给定日期之间的差异。我在 blade
中执行以下操作
\Carbon\Carbon::parse(Auth::user()->properties->first()->von)->diffForHumans()
但是这个 returns 只有年份,所以以下面的例子为例,其中给定的日期是 1st September, 2011
我得到的结果是 6 年前 预期是 6 年零 3 个月。
有可能用 Carbon 实现吗?
您可以使用 diff()
及其属性:
$diff = auth()->user()->properties->first()->von->diff(now());
然后显示出来:
The difference is {{ $diff->y }} years and {{ $diff->m }} months
或者,您可以得到不同的月份并使用它:
$diffInMonths = auth()->user()->properties->first()->von->diffInMonths(now());
我尝试在 Laravel 应用中使用 Carbon 获取 2 个日期之间的差异,即日期 now() 和给定日期之间的差异。我在 blade
中执行以下操作\Carbon\Carbon::parse(Auth::user()->properties->first()->von)->diffForHumans()
但是这个 returns 只有年份,所以以下面的例子为例,其中给定的日期是 1st September, 2011
我得到的结果是 6 年前 预期是 6 年零 3 个月。
有可能用 Carbon 实现吗?
您可以使用 diff()
及其属性:
$diff = auth()->user()->properties->first()->von->diff(now());
然后显示出来:
The difference is {{ $diff->y }} years and {{ $diff->m }} months
或者,您可以得到不同的月份并使用它:
$diffInMonths = auth()->user()->properties->first()->von->diffInMonths(now());