我正在使用这段代码:
struct timeval tv;
time_t nowtime;
struct tm *nowtm;
char tmbuf[64], buf[64];
gettimeofday(&tv, NULL);
nowtime = tv.tv_sec;
nowtm = localtime(&nowtime);
strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm);
snprintf(buf, sizeof buf, "%s.%06d", tmbuf, tv.tv_usec);
从这个答案:
https://stackoverflow.com/a/2409054/997112
将 struct timeval 打印为可读格式。但是,我收到此编译器警告:
warning: format '%06d' expects type 'int', but argument 5 has type '__suseconds_t'
有人可以帮忙吗?