note 71600 rejected from function.strptime by nlopess
| From: | nlopess@php.net | Date: | Thu, 07 Dec 2006 18:17:57 +0000 |
| Subject: | note 71600 rejected from function.strptime by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-120405@lists.php.net to get a copy of this message | ||
Note Submitter: rush at natm dot ru
----
WARNING ! BUG ! strptime( '%m' ) returns 00-11, but by documentation 01-12 !!! So,
ISO-8601=>UNIX for example looks like follows:
NB: "$tm['tm_mon'] + 1" in mktime() call !
<?
function iso2unix( $strdate ) {
$tm = strptime( $strdate, '%Y-%m-%dT%T' );
return mktime( $tm['tm_hour'], $tm['tm_min'], $tm['tm_sec'],
$tm['tm_mon'] + 1, $tm['tm_mday'], $tm['tm_year'] );
}
$start = getdate( iso2unix( '2006-12-07T13:23:07.103' ) );
var_dump( $start );
// result
array(11) {
"seconds"=> 7,
"minutes"=> 23,
"hours"=> 13,
"mday"=> 7,
"wday"=> 4,
"mon"=> 12,
"year"=> 2006,
"yday"=> 340,
"weekday"=> "Thursday",
"month"=> "December",
0=> 1165486987
}
?>