Output is in seconds. convert to hh:mm:ss format in php

后端 未结 13 1745
礼貌的吻别
礼貌的吻别 2020-12-01 13:54
  1. My output is in the format of 290.52262423327 seconds. How can i change this to 00:04:51?

  2. The same output i want to show in seconds and in HH:MM:SS

13条回答
  •  半阙折子戏
    2020-12-01 14:00

    Try this :)

    private function conversionTempsEnHms($tempsEnSecondes)
        {
            $h = floor($tempsEnSecondes / 3600);
            $reste_secondes = $tempsEnSecondes - $h * 3600;
    
            $m = floor($reste_secondes / 60);
            $reste_secondes = $reste_secondes - $m * 60;
    
            $s = round($reste_secondes, 3); 
            $s = number_format($s, 3, '.', '');
    
            $h = str_pad($h, 2, '0', STR_PAD_LEFT);
            $m = str_pad($m, 2, '0', STR_PAD_LEFT);
            $s = str_pad($s, 6, '0', STR_PAD_LEFT);
    
            $temps = $h . ":" . $m . ":" . $s;
    
            return $temps;
        }
    

提交回复
热议问题