0

I want to output a "race time" format like "1:03:57.311" Hour:Minutes:Seconds:Microsecond My input format are seconds (float) like 3837.3113

So how can I format the seconds like "3837.3113" to this "race time" format: 1:03:57.311 with PHP?

Solution:

function format_race_time($t,$f=':') // t = seconds, f = separator 
{
  return sprintf("%02d%s%02d%s%02d%s%02d", floor($t/3600), $f, ($t/60)%60, $f, $t%60, $f, round(($t-round($t))*1000));
}
CodeSuey
  • 1
  • 2
  • [Convert seconds to Hour:Minute:Second](https://stackoverflow.com/q/3172332/1427878) helps you convert the seconds, and the millisecond part you can simply extract from the float value and append as-is. – CBroe May 10 '22 at 14:36
  • But microseconds are missing. And that ist the problem. – CodeSuey May 10 '22 at 15:02

0 Answers0