You can get the expected result using the class Datetime, take the example:
We created a function to facilitate use:
function converterSegundos($segundos, $formato) {
$dtF = new \DateTime('@0');
$dtT = new \DateTime("@$segundos");
return $dtF->diff($dtT)->format($formato);
}
Now to use simply call the function informing a format, below returns in seconds.
// 6 segundos
echo converterSegundos(6, '%s segundos');
Now only minutes:
// 6 minutos
echo converterSegundos(369, '%i minutos');
You can return the time:
// 10 horas
echo converterSegundos(36000, '%h horas');
You can return the days:
// 60 dias
echo converterSegundos(5184000, '%a dias');
Or
// 60 dias, 0 horas, 0 minutos e 0 segundos
echo converterSegundos(5184000, '%a dias, %h horas, %i minutos e %s segundos');
See working on repl it.
Reference
You’re turning days into minutes, not seconds into days
– Jefferson Quesado
Hello, it didn’t work....
– user89739