craigbabe Posted June 7, 2006 Share Posted June 7, 2006 Hey I was wondering how I could change the outputed 15600 seconds into the number ofd hours minutes and seconds? I need this for a count down feature.Is there a function that can do this? I have looked around but only confused myself Link to comment https://forums.phpfreaks.com/topic/11396-changing-time-stamp-into-hours-minutes-seconds/ Share on other sites More sharing options...
ober Posted June 7, 2006 Share Posted June 7, 2006 No function I know of... you'll just have to do a little math.[code]$hours = floor($total_secs / 3600);$min = floor(($total_secs % 3600) / 60);$sec = floor(($total_secs % 3600) % 60);[/code]Heh... I just came up with that... I might have to use that somewhere. Link to comment https://forums.phpfreaks.com/topic/11396-changing-time-stamp-into-hours-minutes-seconds/#findComment-42775 Share on other sites More sharing options...
obsidian Posted June 7, 2006 Share Posted June 7, 2006 [!--quoteo(post=380974:date=Jun 7 2006, 08:41 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 7 2006, 08:41 AM) [snapback]380974[/snapback][/div][div class=\'quotemain\'][!--quotec--]No function I know of... you'll just have to do a little math.[code]$hours = floor($total_secs / 3600);$min = floor(($total_secs % 3600) / 60);$sec = floor(($total_secs % 3600) % 60);[/code]Heh... I just came up with that... I might have to use that somewhere.[/quote]lol... very similar to what i wrote up earlier this morning, too, ober... i was a little more verbose to aid in understanding, though:[code]function getTimeDiff($ts1, $ts2) { $diff = abs($ts1 - $ts2); $sec = 1; $min = $sec * 60; $hour = $min * 60; $day = $hour * 24; $dayDiff = floor($diff / $day); $diff = $diff % $day; $hourDiff = floor($diff / $hour); $diff = $diff % $hour; $minDiff = floor($diff / $min); $secDiff = $diff % $min; return "$dayDiff days $hourDiff hours $minDiff mins $secDiff seconds";}echo getTimeDiff(time(), mktime(0,0,0,12,2,2005));[/code] Link to comment https://forums.phpfreaks.com/topic/11396-changing-time-stamp-into-hours-minutes-seconds/#findComment-42777 Share on other sites More sharing options...
ober Posted June 7, 2006 Share Posted June 7, 2006 Bah... they didn't ask about days... and I'm results oriented... EFFICIENCY IS KEY! ;-) Link to comment https://forums.phpfreaks.com/topic/11396-changing-time-stamp-into-hours-minutes-seconds/#findComment-42778 Share on other sites More sharing options...
obsidian Posted June 7, 2006 Share Posted June 7, 2006 [!--quoteo(post=380977:date=Jun 7 2006, 08:47 AM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 7 2006, 08:47 AM) [snapback]380977[/snapback][/div][div class=\'quotemain\'][!--quotec--]Bah... they didn't ask about days... and I'm results oriented... EFFICIENCY IS KEY! ;-)[/quote]lol... i know, but in the thread i answered with that function, they DID ask about days ;-) Link to comment https://forums.phpfreaks.com/topic/11396-changing-time-stamp-into-hours-minutes-seconds/#findComment-42804 Share on other sites More sharing options...
redarrow Posted June 7, 2006 Share Posted June 7, 2006 I read the post and thinking issint it better to insert the data in this format $count_down_time=date("hms");and then use a for loop to count down. Link to comment https://forums.phpfreaks.com/topic/11396-changing-time-stamp-into-hours-minutes-seconds/#findComment-42817 Share on other sites More sharing options...
kenrbnsn Posted June 7, 2006 Share Posted June 7, 2006 Here's a function I just came up with that uses the standard date() and strtotime() functions:[code]<?phpfunction get_hms($secs) { if ($secs > 86400) return (false); $mid = strtotime(date('Y-m-d 00:00:00',strtotime('now'))); list($hns['hour'],$hms['min'],$hms['sec']) = explode(':', date('G:i:s',$mid + $secs)); return($hms);}?>[/code]Returns an array containing the number of Hours, Minutes, Second or FALSE if the input number is more than a day (86,400 seconds).Ken Link to comment https://forums.phpfreaks.com/topic/11396-changing-time-stamp-into-hours-minutes-seconds/#findComment-42827 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.