seconds to hh:mm:ss format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
new2phpcode
Forum Newbie
Posts: 21
Joined: Tue Oct 09, 2007 10:40 pm

seconds to hh:mm:ss format

Post by new2phpcode »

is there a function that will convert seconds in hh:mm:ss format in php? :?:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

gmdate() might suffice.

Code: Select all

<?php
$seconds = 78432;
echo gmdate('H:i:s', $seconds), "\n";
echo gmdate('d H:i:s', $seconds), "\n\n";

$seconds = 78432 + 9876;
echo gmdate('H:i:s', $seconds), "\n";
echo gmdate('d H:i:s', $seconds), "\n\n";
?>
21:47:12
01 21:47:12

00:31:48
02 00:31:48
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

check out the top comment in the manual page for the datetime functions:
http://www.php.net/manual/en/ref.datetime.php#78025

Those comments are GOLD for newbies!
new2phpcode
Forum Newbie
Posts: 21
Joined: Tue Oct 09, 2007 10:40 pm

Post by new2phpcode »

actually what i have done previously is correct using gmdate, but i just need the hh:mm:ss, for example i have 7098640.375 secs. the results should be something like 2019:10:07, actually i have done it manually..... well maybe in php there is, i hope so... :) thanks for the reply... :D .
new2phpcode
Forum Newbie
Posts: 21
Joined: Tue Oct 09, 2007 10:40 pm

Post by new2phpcode »

i guess, ill just convert the value in hours round it off, then use explode for the minutes and seconds... :D
Post Reply