首页 > 解决方案 > How to add different timestamp

问题描述

I'm having a problem adding two(2) timestamp for example:

00:30:00
00:45:31
========
01:15:31 

I can't figure it out how to do it using laravel with carbon...

标签: phplaravellaravel-5php-carbon

解决方案


You can't add time like they are integer. One of the way is to convert it to another format and then add it. After adding them, convert it back to time type.

For example, try this:

$time1 = "00:30:00";
$time2 = "00:45:31";

$secs = strtotime($time2) - strtotime("00:00:00");
$result = date("H:i:s", strtotime($time1) + $secs);

dd($result); // "01:15:31"

推荐阅读