note 22991 deleted from function.date by sniper
| From: | sniper@php.net | Date: | Sat, 18 Jan 2003 01:33:50 +0000 |
| Subject: | note 22991 deleted from function.date by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-42318@lists.php.net to get a copy of this message | ||
Here is function that will convert seconds to h:m:s and vice versa. The date functions all seemed
to want actual dates so I wrote this function:
function parsefortime ($u) {
//Strip out letters
$u=ereg_replace("[a-zA-z]","",$u);
if (ereg("[^0-9]",$u)) {
$result = 0;
//Use whatever delimeter is there.
$u=split("[^0-9]",$u);
$result += array_pop($u) * 1; //Seconds
$result += array_pop($u) * 60; //Minutes
$result += array_pop($u) * 3600; //Hours
} else {
$hours = floor($u / 3600);
$u -= $hours * 3600;
$minutes = floor($u / 60);
$u -= $minutes * 60;
$seconds = $u;
$result = $hours.':'.$minutes.':'.$seconds;
}
return $result;
}