php strptime未定义,PHP strptime format bug?

If you think the problem is on MacOS X and in the C library, then you could produce a test case to demonstrate it. For example, I ran the code below on MacOS X 10.4.11 (PPC, G4, 32-bit), and got the output:

Now: 1225573977

Formatted (12): 011120082112

End: 0xBFFFF553 (Buffer: 0xBFFFF547)

Then: year = 2008, month = 11, day = 1, hour = 21, minute = 12

Reformatted (12): 011120082112

The code I used is:

#include

#include

int main(void)

{

time_t now = time(0);

struct tm *tm = gmtime(&now);

char format[] = "%d%m%Y%H%M";

char buffer1[64];

char buffer2[64];

size_t f_len = strftime(buffer1, sizeof(buffer1), format, tm);

struct tm then;

char *end = strptime(buffer1, format, &then);

size_t p_len = strftime(buffer2, sizeof(buffer2), format, &then);

printf("Now: %ld\n", (long)now);

printf("Formatted (%lu): %s\n", (unsigned long)f_len, buffer1);

printf("End: 0x%08lX (Buffer: 0x%08lX)\n", (unsigned long)end, (unsigned long)buffer1);

printf("Then: year = %d, month = %d, day = %d, hour = %d, minute = %d\n",

then.tm_year + 1900, then.tm_mon + 1, then.tm_mday, then.tm_hour, then.tm_min);

printf("Reformatted (%lu): %s\n", (unsigned long)p_len, buffer2);

return(0);

}

On the basis of what I see, there is no bug in strptime() in the version I'm using. We can debate about the merits of the non-existent error checking, and of the casts versus C99 notations in the printing, but I think the code is accurate enough. I used gmtime() instead of localtime(); I doubt if that was a factor in not reproducing the problem.

Maybe you should look at the PHP test suite?

Maybe you should split your rather complex expression into pieces to detect where the error occurs in PHP?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值