【问题标题】:strptime returning unexpected resultsstrptime 返回意外结果
【发布时间】:2009-10-26 18:24:14
【问题描述】:

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

我在这里错过了什么??

【问题讨论】:

    标签: c datetime


    【解决方案1】:

    它的千年虫!

    将 1900 添加到年份。月份为 0 索引。

    【讨论】:

    • 哇...我的手掌拍打我脸的声音可能会传到数英里之外...感谢您的快速响应
    猜你喜欢
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    相关资源
    最近更新 更多