c - strptime 返回意外结果

标签 c datetime

我对 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/

相关文章:

c - 将链表数组传递给函数

c - 是否允许在分配的内存区域中以非 sizeof 偏移量创建对象?

c++ - 用于获取 URL 之类的简单 C++(或 c)库

c++ - 如何解析包含小数时间的日期时间字符串?

ctime 随机返回 NULL

c# - 使用 PST/CEST/UTC/等形式的时区解析 DateTime

c - 负数的位运算

c++ - 使用 ctypes 将结构传递给 native 库时遇到问题

java - 如何确定 J2ME 中明天的日期以在 DateField 中使用?

python - 二月 Dateutil 的解析器不解析