search

Home  >  Q&A  >  body text

Convert seconds to hours:minutes:seconds

I need to convert seconds to "hour:minute:second".

For example: "685" is converted to "00:11:25"

How can I achieve this goal?

P粉752290033P粉752290033274 days ago643

reply all(2)I'll reply

  • P粉799885311

    P粉7998853112024-03-26 15:16:51

    An hour is 3600 seconds and a minute is 60 seconds, why not:

    produce:

    $ php file.php
    0:11:25

    (I didn't test this much, so there may be errors with floors etc.)

    reply
    0
  • P粉301523298

    P粉3015232982024-03-26 12:02:34

    You can use gmdate() function:

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

    reply
    0
  • Cancelreply