Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggregation Enquires Welcome

Convert Seconds to HH:MM:SS

The following will convert seconds to an HH:MM:SS format.

$result = gmdate('H:i:s', ($seconds));

To add the 's' for seconds (it puts the time into perspective), use:

$result = gmdate('H:i:s', ($seconds)) . 's';

For anything under a minute, you might want to strip the leading 00:00.

$result = ltrim(gmdate('H:i:s', ($seconds)), '00:') . 's';

While printing an 's' gives the time a reference, you might want to keep the leading 00: at times even when there's no hour. Use the following:

$result = ltrim(gmdate('H:i:s', ($seconds)), '00:00:') . 's';

■ ■ ■

Reference: PHP Manual, time() and date() .

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment