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

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

    For till 23:59:59 hours you can use PHP default function

    echo gmdate("H:i:s", 86399);
    

    Which will only return the result till 23:59:59

    If your seconds is more then 86399 than with the help of @VolkerK answer

    $time = round($seconds);
    echo sprintf('%02d:%02d:%02d', ($time/3600),($time/60%60), $time%60);
    

    will be the best options to use ...

提交回复
热议问题