pianoman993 Posted August 22, 2008 Share Posted August 22, 2008 Hello, I believe I have a fairly simple question about converting time. I currently have a variable containing a number of seconds. Is there any way I could format that number of seconds so that it displays as something like 00:00:10. So for example if I have a variable containing 10 seconds, how could I format that to display the 10 seconds as 00:00:10? Thanks a bunch in advance for any help. :-D - Mark Quote Link to comment Share on other sites More sharing options...
Maq Posted August 22, 2008 Share Posted August 22, 2008 Try this function: function split_seconds($seconds) { // get the minutes $minutes = floor($seconds / 60) ; $seconds_left = $seconds % 60 ; // get the hours $hours = floor($minutes / 60) ; $minutes_left = $minutes % 60 ; // (test) show the result echo "$hours : $minutes_left : $seconds_left" ; } split_seconds(68648) ; ?> Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 22, 2008 Share Posted August 22, 2008 this is simple math: $time = 10; $hours = floor($time / 3600); $minutes = floor(($time % 3600) / 60); $seconds = $time - $hours*3600 - $minutes*60; $formatted = sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds); i'll admit i haven't tested it, but give it a shot. EDIT: beaten to it, but here's another way to skin the cat. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.