Convert seconds to Hour:Minute:Second

前端 未结 27 2623
说谎
说谎 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:37

    Other solutions use gmdate, but fail in edge cases where you have more than 86400 seconds. To get around this, we can simply compute the number of hours ourselves, then let gmdate compute the remaining seconds into minutes/seconds.

    echo floor($seconds / 3600) . gmdate(":i:s", $seconds % 3600);
    

    Input: 6030 Output: 1:40:30

    Input: 2000006030 Output: 555557:13:50

提交回复
热议问题