How to get difference between $timeNow and $timeFuture?

748 views Asked by At

How to get difference between $timeNow and $timeFuture with Laravel and display in format "H:i:s" ?

Or how to make countdown with JS from $timeNow to $timeFuture and display in format "H:i:s" ?

1

There are 1 answers

0
baao On

Using Carbon's diffInSeconds method and gmdate(), you can get it like this:

$timeNow = \Carbon::now();
$timeFuture = \Carbon::now()->addSeconds(7500);

echo gmdate("H:i:s", $timeNow->diffInSeconds($timeFuture));