c语言 --- printf time_t 注意点

先看看写的测试代码

#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。

posted @ 2012-10-18 16:07  Mingxx  阅读(11134)  评论(1编辑  收藏  举报