如何在 laravel 5.1 中获得 created_at 和 updated_at 的差异

How to get the difference of created_at and updated_at in laravel 5.1

我已经在互联网上进行了研究,但我发现的只是过去的时间 (e.g. 4mins ago)我想要的 是与 [=15] 的区别=] 和 updated_at 在我的数据库中,像这样, 3days 3hrs 23mins 30sec 如果没有 minshrs,只输出 3days 3hrs 30sec3days 23mins 30sec

我有:

查看

@foreach($submits as $submit)
   {{ $submit->pivot->created_at }} // to get the created_at
   {{ $submit->pivot->updated_at }} // to get the updated_at
@endforeach

您可以使用此函数查找天、小时、分钟和秒。

public function getDifference($created_at, $updated_at) {
    $days = $created_at->diffInDays($updated_at);
    $hours = $created_at->diffInHours($updated_at->subDays($days));
    $minutes = $created_at->diffInMinutes($updated_at->subHours($hours));
    $seconds = $created_at->diffInSeconds($updated_at->subMinutes($minutes));
    return CarbonInterval::days($days)->hours($hours)->minutes($minutes)->seconds($seconds)->forHumans();
}

输出

3 days 3 hours 23 minutes 30 seconds