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

后端 未结 13 1753
礼貌的吻别
礼貌的吻别 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:09

    1)

    function foo($seconds) {
      $t = round($seconds);
      return sprintf('%02d:%02d:%02d', ($t/3600),($t/60%60), $t%60);
    }
    
    echo foo('290.52262423327'), "\n";
    echo foo('9290.52262423327'), "\n";
    echo foo(86400+120+6), "\n";
    

    prints

    00:04:51
    02:34:51
    24:02:06
    

    2)

    echo round($time, 2);
    

提交回复
热议问题