我试图得到两个日期之间的差异,日期现在()和一个给定的日期在Laravel应用程序的碳。我在我的刀刃上做下面的事情
\Carbon\Carbon::parse(Auth::user()->properties->first()->von)->diffForHumans()但这只返回年份,因此,以下面的示例为例,在给定日期为1st September, 2011的情况下,我在6年前得到的结果是,预期为6年零3个月。有可能用碳来实现这一目标吗?
发布于 2017-12-11 15:10:31
您可以使用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());https://stackoverflow.com/questions/47755681
复制相似问题