Re: Seconds to minutes
| From: | Morgan Hughes | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: Seconds to minutes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-125176@lists.php.net to get a copy of this message | ||
On Wed, 20 Nov 2002, 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?
How about something like this, given $seconds containing the number of
seconds?
$secs = $seconds;
$hours = $secs / 3600;
$secs %= 3600;
$mins = $secs / 60;
$mins %= 60;
$out = sprintf ("%d hour%s, %d minute%s, %d second%s",
$hours, ($hours == 1 ? '' : 's'),
$mins, ($mins == 1 ? '' : 's'),
$secs, ($secs == 1 ? '' : 's'));
--
Morgan Hughes
C programmer and highly caffeinated mammal.
kyhm@kyhm.com
ICQ: 79293356