php strptime未定义,PHP: strptime - Manual

该博客介绍了一种在Windows环境下重新实现PHP的strptime函数的方法,使得在Windows上也能解析特定日期和时间格式(%S, %M, %H, %d, %m, %Y)。作者Lionel SAURON提供了完整的代码实现,允许用户在无法使用原版strptime函数的情况下进行日期和时间的解析。
摘要由CSDN通过智能技术生成

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 :

* 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 $sDate parsed, or false on error.

*/if(function_exists("strptime") ==false)

{

functionstrptime($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 errorif(($nParsedDateTimestamp===false)

||($nParsedDateTimestamp=== -1)) returnfalse;$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)?>

data = ['2023-05-10 20:37:49', '2023-05-10 20:37:50', '2023-05-10 20:37:51', '2023-05-10 20:37:52', '2023-05-10 20:37:53', '2023-05-10 20:37:54', '2023-05-10 20:37:55', '2023-05-10 20:37:56', '2023-05-10 20:37:57', '2023-05-10 20:37:58', '2023-05-10 20:37:59', '2023-05-10 20:38:00', '2023-05-10 20:38:01', '2023-05-10 20:38:02', '2023-05-10 20:38:03', '2023-05-10 20:38:04', '2023-05-10 20:38:05', '2023-05-10 20:38:06', '2023-05-10 20:38:07', '2023-05-10 20:38:08', '2023-05-10 20:38:09', '2023-05-10 20:38:10', '2023-05-10 20:38:11', '2023-05-10 20:38:12', '2023-05-10 20:38:13', '2023-05-10 20:38:14', '2023-05-10 20:38:15', '2023-05-10 20:38:16', '2023-05-10 20:38:17', '2023-05-10 20:38:18', '2023-05-10 20:38:19', '2023-05-10 20:38:20', '2023-05-10 20:38:21', '2023-05-10 20:38:22', '2023-05-10 20:38:23', '2023-05-10 20:38:24', '2023-05-10 20:38:25', '2023-05-10 20:38:26', '2023-05-10 20:38:27', '2023-05-10 20:38:28', '2023-05-10 20:59:25', '2023-05-10 20:59:26', '2023-05-10 20:59:27', '2023-05-10 20:59:28', '2023-05-10 20:59:29', '2023-05-10 20:59:30', '2023-05-10 20:59:31', '2023-05-10 20:59:32', '2023-05-10 20:59:33', '2023-05-10 20:59:34', '2023-05-10 20:59:35', '2023-05-10 20:59:36', '2023-05-10 20:59:37', '2023-05-10 20:59:38', '2023-05-10 20:59:39', '2023-05-10 20:59:40', '2023-05-10 20:59:41', '2023-05-10 20:59:42', '2023-05-10 20:59:43', '2023-05-10 20:59:44', '2023-05-10 20:59:45', '2023-05-10 20:59:46', '2023-05-10 20:59:47', '2023-05-10 20:59:48', '2023-05-10 20:59:49', '2023-05-10 20:59:50', '2023-05-10 20:59:51', '2023-05-10 20:59:52', '2023-05-10 20:59:53', '2023-05-10 20:59:54', '2023-05-10 20:59:55', '2023-05-10 20:59:56', '2023-05-10 20:59:57', '2023-05-10 20:59:58', '2023-05-10 20:59:59', '2023-05-10 21:00:00'] 在data里面我想筛选出2023-05-09 18:04:13到2023-05-09 23:47:24之前的数据也包括2023-05-09 18:04:13和2023-05-09 23:47:24该怎么做
最新发布
05-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值