{Carbon} Convert time in HH:MM:SS format into seconds in Laravel?

Viewed 22613

I want to convert the time which I got from $scheduleTime = Carbon::createFromTimestampUTC($scheduleTimestamp)->toTimeString(); which is currently giving me 07:32:40 now I want to convert it into seconds only using Carbon library is this possible to do so if yes then how?

5 Answers

you could use

$scheduleTime =\Carbon\Carbon::createFromTimestampUTC($scheduleTimestamp)->diffInMinutes()

to display the time in minute or

$scheduleTime =\Carbon\Carbon::createFromTimestampUTC($scheduleTimestamp)->diffInSeconds() 

to display it in second

private function convertTimeToSecond(string $time): int
{
    $d = explode(':', $time);
    return ($d[0] * 3600) + ($d[1] * 60) + $d[2];
}

Example, after 2 year...

Related