note 22991 added to function.date
| From: | wtfo at technocraft dot com | Date: | Sat, 06 Jul 2002 03:37:22 +0000 |
| Subject: | note 22991 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-32665@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;
}
--
http://www.php.net/manual/en/function.date.php
http://master.php.net/manage/user-notes.php?action=edit+22991
http://master.php.net/manage/user-notes.php?action=delete+22991
http://master.php.net/manage/user-notes.php?action=reject+22991