我对 C 还是很陌生,正在尝试学习如何使用 strptime 看看它是否适用于项目的一部分,但我什至无法让一个看起来非常基本的示例正常工作......
int main()
{
struct tm *t;
t = (struct tm *) malloc(sizeof(struct tm));
memset(t, 0, sizeof(t));
if (strptime("12-2009", "%m-%Y", t) != NULL)
printf("month: %d year: %d\n",t->tm_mon, t->tm_year);
free(t);
return 0;
}
运行这个程序给出:“月:11 年:109”
我在这里错过了什么??
最佳答案
是千年虫!
将 1900 添加到年份。月份为 0 索引。
关于c - strptime 返回意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1626461/