先看看写的测试代码

#include <stdio.h>
#include <time.h>

int main(int argc, char* argv[])
{
    time_t now;

    time(&now);
    printf("size of time_t: %d\r\n", sizeof(time_t)); //1
    printf("%d -> %d\r\n", now, now); //Error 2.
    printf("%I64d -> %I64d\r\n", now, now); // for windows 3.
    printf("%lld -> %lld\r\n", now, now); // for linux 4.
    return 0;
}

输出:

size of time_t: 8
1350547419 -> 0
1350547419 -> 1350547419
1350547419 -> 1350547419

原因:

  第二个printf参数把把time_t结构分成了两个32位的INT。所以这二个参数为0。

相关文章:

  • 2021-06-15
  • 2021-05-31
  • 2022-12-23
  • 2021-12-04
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-10-26
  • 2022-12-23
相关资源
相似解决方案