How to convert seconds to time format?

Dewan159 picture Dewan159 · Oct 4, 2010 · Viewed 157.8k times · Source

For some reason I convert a time format like: 03:30 to seconds 3*3600 + 30*60, now. I wanna convert it back to its first (same) format up there. How could that be?

My attempt:

3*3600 + 30*60 = 12600 

12600 / 60 = 210 / 60 = 3.5, floor(3.5) = 3 = hour

Now, what about the minutes?

Considering the value can be like 19:00 or 02:51. I think you got the picture.

And by the way, how to convert 2:0 for example to 02:00 using RegEx?

Answer

CyberJunkie picture CyberJunkie · Jun 7, 2012

This might be simpler

gmdate("H:i:s", $seconds)

PHP gmdate