Convert seconds to Hour:Minute:Second

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

    The gmtdate() function didn't work for me as I was tracking hours worked on a project and if it's over 24 hours, you get amount left over after 24 hours is subtracted. In other words 37 hours becomes 13 hours. (all as stated above by Glavic - thanks for your examples!) This one worked well:

    Convert seconds to format by 'foot' no limit :
    $seconds = 8525;
    $H = floor($seconds / 3600);
    $i = ($seconds / 60) % 60;
    $s = $seconds % 60;
    echo sprintf("%02d:%02d:%02d", $H, $i, $s);
    # 02:22:05
    

提交回复
热议问题