note 72980 deleted from function.strptime by nlopess
| From: | nlopess@php.net | Date: | Mon, 05 Mar 2007 16:37:49 +0000 |
| Subject: | note 72980 deleted from function.strptime by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124104@lists.php.net to get a copy of this message | ||
Note Submitter: php at r-o-b-e-r-t dot de
----
my function to convert a timestamp from a GPX file.
If you only need the time, then you can leave the date blank (duration, etc.)
But there is one confusing thing: i always have to add one month in the strf-array
function convertDate($time, $date = "") {
if (!strlen($date)) {
$format = '%H:%M:%S';
} elseif ( is_numeric($date[3])) { // 18-Dec-06 10:29:32
$format = '%d-%m-%y %H:%M:%S';
} else { // 18-12-06 10:29:32
$format = '%d-%b-%y %H:%M:%S';
}
$ts = trim($date . " " . $time);
if($strf = strptime($ts, $format)) {
// @todo: I don't, why i had to add 1 month .. but for the moment, its ok
if (!strlen($date)) {
return $strf["tm_hour"]*3600 + $strf["tm_min"] * 60 +
$strf["tm_sec"];
} else {
return mktime($strf["tm_hour"], $strf["tm_min"], $strf["tm_sec"],
$strf["tm_mon"]+1, $strf["tm_mday"], $strf["tm_year"]);
}
} else {
return false;
}
}