convert seconds into formatted time | Codeexecute

convert seconds into formatted time

function convertTime($sec) {
$dta = new \DateTime('@0');
$dtb = new \DateTime("@$sec");
return $dta->diff($dtb)->format('%a days, %h hours, %i minutes and %s seconds');
}