1
为什么用time()报告的时间有时比C代码中的timespec_get()的秒部分晚1秒?
以下代码段: struct timespec ts; for (int x = 0; x < 100000000; x++) { timespec_get(&ts, TIME_UTC); long cTime = (long) time(NULL); if (cTime != ts.tv_sec && ts.tv_nsec < 3000000) { printf("cTime: %ld\n", cTime); printf("ts.tv_sec: %ld\n", ts.tv_sec); printf("ts.tv_nsec: %ld\n", ts.tv_nsec); } } 产生以下输出: ... cTime: 1579268059 ts.tv_sec: 1579268060 ts.tv_nsec: 2527419 cTime: …