先看看寫的測試代碼
#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。