bachx Posted September 6, 2007 Share Posted September 6, 2007 I have a a UNIX format number that I want to convert into an Hours:Minutes:Seconds format for a stopwatch/countdown timer script I'm writing. I used date("H:i:s", ($time)), but the problem is, if the period I'm counting is above 24 hours, the Hours reset to 0. So If I was counting down 49 Hours, It's be displayed as 01:00:00 instead of 49:00:00. Any help? Link to comment https://forums.phpfreaks.com/topic/68284-solved-time-format-help/ Share on other sites More sharing options...
Jessica Posted September 6, 2007 Share Posted September 6, 2007 You'll need to figure out how many hours, minutes and seconds are left manually, using math. Link to comment https://forums.phpfreaks.com/topic/68284-solved-time-format-help/#findComment-343308 Share on other sites More sharing options...
bachx Posted September 6, 2007 Author Share Posted September 6, 2007 I already have the total number of seconds (in unix format) for the time left, I just need to convert it into H:i:s format without it resetting every 24 hours. Link to comment https://forums.phpfreaks.com/topic/68284-solved-time-format-help/#findComment-343310 Share on other sites More sharing options...
Jessica Posted September 6, 2007 Share Posted September 6, 2007 You'll need to figure out how many hours, minutes and seconds are left manually, using math. Link to comment https://forums.phpfreaks.com/topic/68284-solved-time-format-help/#findComment-343311 Share on other sites More sharing options...
sneamia Posted September 6, 2007 Share Posted September 6, 2007 Post your current script and I'll do it for you. Link to comment https://forums.phpfreaks.com/topic/68284-solved-time-format-help/#findComment-343320 Share on other sites More sharing options...
bachx Posted September 6, 2007 Author Share Posted September 6, 2007 Thanks. There is no 'script', I simply have a variable called $time which has the remaining time in seconds. I know dividing that on 3600 returns the number of hours. What about minutes/seconds? Link to comment https://forums.phpfreaks.com/topic/68284-solved-time-format-help/#findComment-343332 Share on other sites More sharing options...
sneamia Posted September 6, 2007 Share Posted September 6, 2007 <?php $t = htmlentities($_GET['t']); $time['days'] = (int) ($t / (60 * 60 * 24)); $t = $t % (60 * 60 * 24); $time['hours'] = (int) ($t / (60 * 60)); $t = $t % (60 * 60); $time['minutes'] = (int) ($t / 60); $time['seconds'] = $t % 60; // output style 1 foreach ($time as $key => $value) { if (!empty($value)) { echo "$value $key "; } } // output style 1 end echo '<br />'; // output style 2 $time['hours'] += $time['days'] * 24; foreach ($time as $key => $value) { if (strlen($time[$key]) == 1) { $time[$key] = '0' . $value; } } echo $time['hours'] . ':' . $time['minutes'] . ':' . $time['seconds']; // output style 2 end ?> http://sneamia.net/junk/bachx/?t=100 Link to comment https://forums.phpfreaks.com/topic/68284-solved-time-format-help/#findComment-343355 Share on other sites More sharing options...
bachx Posted September 7, 2007 Author Share Posted September 7, 2007 Awesome, thanks. Link to comment https://forums.phpfreaks.com/topic/68284-solved-time-format-help/#findComment-343375 Share on other sites More sharing options...
sneamia Posted September 7, 2007 Share Posted September 7, 2007 Remember to hit topic solved. Link to comment https://forums.phpfreaks.com/topic/68284-solved-time-format-help/#findComment-343390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.