RE: [PHP] Script to convert # of seconds to HH:mm
| From: | Javier Muniz | Date: | Mon, 19 Mar 2001 22:52:26 +0000 |
| Subject: | RE: [PHP] Script to convert # of seconds to HH:mm | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-44640@lists.php.net to get a copy of this message | ||
should probably be:
function philtime($time) {
$hours = ($time - ($time % 3600)) / 3600;
$min = (int) (($time % 3600) / 60);
return ("$hours:$min");
}
This way you don't risk rounding up on your first cast to int and being off
by an hour... rounding is ok, however, for minutes since that is your most
granular interval.
-jm
-----Original Message-----
From: Phillip Bow [mailto:philb@oreilly.com]
Sent: Monday, March 19, 2001 2:43 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Script to convert # of seconds to HH:mm
function philtime($time){
$hours = (int) ($time / 3600);
$min = (int) (($time % 3600) / 60 );
return ("$hours:$min");
}
Should be 3600 since:
60sec = 1min
60min = 1hour
60 * 60 = 3600sec/hour
--
phill
> How about something like this:
>
> $secs = number of seconds;
> $hours = intval($secs/360);
> $minutes = intval(($secs-$hours*360)/60)
> $seconds = $secs - $hours*360 - $minutes * 60;
>
> Hope this helps.
>
> Michael Ridinger
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net