我已经在互联网上进行了研究,但我发现只是过去的时间(e.g. 4mins ago)
,我想要的是为了与created_at
和{{ 1}}在我的数据库中,如果没有updated_at
或3days 3hrs 23mins 30sec
,mins
和,只输出hrs
或{{1} }}。
我有什么:
视图
3days 3hrs 30sec
答案 0 :(得分:0)
使用此功能可以找到天,小时,分钟和秒。
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