Re: Need to convert seconds to DD:HH:MM:SS

From: Date: Fri, 19 Sep 2003 22:31:42 +0000
Subject: Re: Need to convert seconds to DD:HH:MM:SS
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-163243@lists.php.net to get a copy of this message
"Jennifer Goodie" <goodie@apollointeractive.com> wrote in message news:NEBBIJJIKBGCCCNKMPBCAEPOJIAA.goodie@apollointeractive.com... > >can't seem to figure > > out how to get the number of days integrated in here for $hh that > > are > 24. > > to days:hours:minutes:seconds... This function works for what it > > does, can > > someone embelish it to handle days too? > > > > function convertToHHMMSS($seconds) > > { > > $hoursPerDay = 24; > > $SecondsPerHour = 3600; > > $SecondsPerMinute = 60; > > $MinutesPerHour = 60; > > > > $hh = intval($seconds / $SecondsPerHour); > > $mm = intval($seconds / $SecondsPerMinute) % $MinutesPerHour; > > $ss = $seconds % $SecondsPerMinute; > > > > return $hh."h:".$mm."m:".$ss."s"; > > } > > Not quite what you're looking for, but I'm sure you can figure out how to > customize it > > function sec2time($sec){ (snip) > This is less code and is tested. $seconds = 86397; // any starting value $days = floor($seconds/86400); $days_mod = $seconds%86400; $hours = floor($days_mod/3600); $hours_mod = $days_mod%3600; $minutes = floor($hours_mod/60); $minutes_mod = $hours_mod%60; $seconds = floor($minutes_mod); - Kevin

« previous php.general (#163243) next »