note 86572 added to function.strptime
| From: | Altar2010 at osu1 dot php dot net | Date: | Fri, 24 Oct 2008 08:45:41 +0000 |
| Subject: | note 86572 added to function.strptime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145682@lists.php.net to get a copy of this message | ||
If you want to parse a date or a /time in windows env, i re-write strptime function for windows.
I use the same param and i return the same think that the original one.
I use sscanf to parde the string.
Only some format can be parsed (%S, %M, %H, %d, %m, %Y)
See this page (because the function is too big for this notes)
http://sauron.lionel.free.fr/?page=php_lib_strptime
preview :
<?php
/**
* Parse a time/date generated with strftime().
*
* This function is the same as the original one defined by PHP (Linux/Unix only),
* but now you can use it on Windows too.
* Limitation : Only this format can be parsed %S, %M, %H, %d, %m, %Y
*
* @author Lionel SAURON
* @version 1.0
* @public
*
* @param $sDate(string) The string to parse (e.g. returned from strftime()).
* @param $sFormat(string) The format used in date (e.g. the same as used in strftime()).
* @return (array) Returns an array with the <code>$sDate</code> parsed, or
<code>false</code> on error.
*/
if(function_exists("strptime") == false)
{
function strptime($sDate, $sFormat)
{
$aResult = array
(
'tm_sec' => 0,
'tm_min' => 0,
'tm_hour' => 0,
'tm_mday' => 1,
'tm_mon' => 0,
'tm_year' => 0,
'tm_wday' => 0,
'tm_yday' => 0,
'unparsed' => $sDate,
);
while($sFormat != "")
{
// ===== Search a %x element, Check the static string before the %x =====
$nIdxFound = strpos($sFormat, '%');
if($nIdxFound === false)
{
// There is no more format. Check the last static string.
$aResult['unparsed'] = ($sFormat == $sDate) ? "" : $sDate;
break;
}
.....
.....
.....
.....
// ===== Create the other value of the result array =====
$nParsedDateTimestamp = mktime($aResult['tm_hour'], $aResult['tm_min'],
$aResult['tm_sec'],
$aResult['tm_mon'] + 1, $aResult['tm_mday'],
$aResult['tm_year'] + 1900);
// Before PHP 5.1 return -1 when error
if(($nParsedDateTimestamp === false)
||($nParsedDateTimestamp === -1)) return false;
$aResult['tm_wday'] = (int) strftime("%w", $nParsedDateTimestamp); // Days
since Sunday (0-6)
$aResult['tm_yday'] = (strftime("%j", $nParsedDateTimestamp) - 1); // Days
since January 1 (0-365)
return $aResult;
} // END of function
} // END if(function_exists("strptime") == false)
?>
----
Server IP: 89.31.146.176
Probable Submitter: 82.241.212.213
----
Manual Page -- http://www.php.net/manual/en/function.strptime.php
Edit -- https://master.php.net/note/edit/86572
Del: integrated -- https://master.php.net/note/delete/86572/integrated
Del: useless -- https://master.php.net/note/delete/86572/useless
Del: bad code -- https://master.php.net/note/delete/86572/bad+code
Del: spam -- https://master.php.net/note/delete/86572/spam
Del: non-english -- https://master.php.net/note/delete/86572/non-english
Del: in docs -- https://master.php.net/note/delete/86572/in+docs
Del: other reasons-- https://master.php.net/note/delete/86572
Reject -- https://master.php.net/note/reject/86572
Search -- https://master.php.net/manage/user-notes.php