Domas Domas - 5 months ago 15
PHP Question

PHP convert specific string to well formated time string

We have a lot of strings for storing the time that it took participants to finish the track. There are basically 2 different types of those strings ( <1 hour and >1hour ):


What would be the most reasonable way to format these strings in PHP before displaying so that they would keep the same standard -
(the first string needs to be

Any help or guindace is much appreciated.


Simple way would be

$time = str_pad($time,8,'00:',STR_PAD_LEFT)

What it does: Fill the string with 00: from left to the full lenght of 8

or $time = strlen($time)==8?$time:"00:$time"

What it does: Check if string is 8 chars then do nothing else add 00:

This are solutions if really only the 2 different types are given.

This wont work: print date('H:i:s',strtotime('54:37'))