Convert seconds to Hour:Minute:Second

前端 未结 27 2147
说谎
说谎 2020-11-22 07:56

I need to convert seconds to \"Hour:Minute:Second\".

For example: \"685\" converted to \"00:11:25\"

How can I achieve this?

27条回答
  •  不思量自难忘°
    2020-11-22 08:41

    Anyone whose looking for this in the future, this gives the format the initial poster asked for.

    $init = 685;
    $hours = floor($init / 3600);
    $hrlength=strlen($hours);
    if ($hrlength==1) {$hrs="0".$hours;}
    else {$hrs=$hours;} 
    
    $minutes = floor(($init / 60) % 60);
    $minlength=strlen($minutes);
    if ($minlength==1) {$mins="0".$minutes;}
    else {$mins=$minutes;} 
    
    $seconds = $init % 60;
    $seclength=strlen($seconds);
    if ($seclength==1) {$secs="0".$seconds;}
    else {$secs=$seconds;} 
    
    echo "$hrs:$mins:$secs";
    

提交回复
热议问题