time - Convert seconds(float) into mm:ss:ms in php -
i have below php function takes time argument in seconds database. seconds of type float(6,1) in database. pass value function below. problem have if have 1655.5 seconds can hour, minutes , seconds. how milliseconds remain.
ie 1655.5 = 27m:35s.5ms
thanks in advance.
<?php function convertto($init) { $hours = ($init / 3600); $minutes = (($init / 60) % 60); $seconds = $init % 60; if($minutes < 10) { $minutes = "0".$minutes; } if($seconds < 10) { $seconds = "0".$seconds; } $milli = /* code ret remaining milliseconds */ $stagetime = "$minutes:$seconds.$milli"; return $stagetime; } ?>
possibly counter-intuitively, easiest way extract milliseconds first step.
simply floor()
initial value, , subtract result input. give right-hand side of decimal point, can multiply 1000 give number of milliseconds - should cast integer ensure resulting string sensible.
function convertto($init) { $secs = floor($init); $milli = (int) (($init - $secs) * 1000); $hours = ($secs / 3600); $minutes = (($secs / 60) % 60); $seconds = $secs % 60; // ...
Comments
Post a Comment