Re: Seconds to minutes
| From: | Support @ Fourthrealm.com | Date: | Wed, 20 Nov 2002 01:27:58 +0000 |
| Subject: | Re: Seconds to minutes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125174@lists.php.net to get a copy of this message | ||
Bob,
Instead of dividing, use modulus to get the exact number of remaining seconds, and then determine the minutes from that.
Here is some code that I've quickly adapted from another language I use, to take the total minutes, and convert it to "hours:minutes" display.
$totalmins = 193;
$showmins = $totalmins%60;
$showhrs = ($totalmins-$showmins)/60;
echo $showhrs.":".$showmins;
I haven't tested this, but it might give you a start. The same concept would apply to converting seconds to minutes...
Peter
At 12:16 PM 11/20/2002 +1100, Bob Irwin wrote:
Its seems far more reliable than what I am using (dividing by 60 for minutes, 3600 for hours and doing rounding, exploding if its not a round number etc). Its only for measuring short times, so Matt's suggestion should work ok. Ideally though, because it will crop up from time to time, it'd be the go to do it right the first time. Anyone else know of a better way? Best Regards Bob Irwin Server Admin & Web Programmer Planet Netcom ----- Original Message ----- From: "John W. Holmes" <holmes072000@charter.net> To: "'Matt'" <mschroebel@epooch.com>; "'Bob Irwin'" <bob@staff.pnc.com.au>; <php-general@lists.php.net> Sent: Wednesday, November 20, 2002 12:09 PM Subject: RE: [PHP] Seconds to minutes- - - - - - - - - - - - - - - - - - - - - Fourth Realm Solutions pbechard@fourthrealm.com http://www.fourthrealm.com Tel: 519-739-1652 - - - - - - - - - - - - - - - - - - - - -You can do something like this: <?php $seconds = 265; $time = date('i s',$seconds); $minSecs = explode(' ',$time); echo "{$minSecs[0]} minutes and {$minSecs[1]} seconds<br>\n"; ?>That doesn't work for anything over 3599 seconds, though... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php