Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 计算laravel中两个日期之间的小时、分钟和秒数_Php_Laravel_Php Carbon - Fatal编程技术网

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,
   }