Php 计算laravel中两个日期之间的小时、分钟和秒数
假设我们必须按如下方式设置日期时间格式的日期:Php 计算laravel中两个日期之间的小时、分钟和秒数,php,laravel,php-carbon,Php,Laravel,Php Carbon,假设我们必须按如下方式设置日期时间格式的日期: $started_at = '2016-07-05 12:29:16'; $ended_at = '2016-07-06 13:30:10'; 15 hours and 50 minutes and 15 seconds 现在我想计算它们的小时数、分数和秒数,如下所示: $started_at = '2016-07-05 12:29:16'; $ended_at = '2016-07-06 13:30:10'; 15 hours and 50
$started_at = '2016-07-05 12:29:16';
$ended_at = '2016-07-06 13:30:10';
15 hours and 50 minutes and 15 seconds
现在我想计算它们的小时数、分数和秒数,如下所示:
$started_at = '2016-07-05 12:29:16';
$ended_at = '2016-07-06 13:30:10';
15 hours and 50 minutes and 15 seconds
我怎样才能用最简单的方式在laravel和使用中做到这一点。试试这个
$t1 = Carbon::parse('2016-07-05 12:29:16');
$t2 = Carbon::parse('2016-07-04 13:30:10');
$diff = $t1->diff($t2);
这会给你
DateInterval {#727
+"y": 0,
+"m": 0,
+"d": 0,
+"h": 22,
+"i": 59,
+"s": 6,
+"weekday": 0,
+"weekday_behavior": 0,
+"first_last_day_of": 0,
+"invert": 1,
+"days": 0,
+"special_type": 0,
+"special_amount": 0,
+"have_weekday_relative": 0,
+"have_special_relative": 0,
}