如果没有Boost,我们怎么能这样做(获得毫秒的本地时间)? 我有这样的事情:
time_of_day = time(NULL);
time_str_tm = localtime(&time_of_day);
printf("\n%02i:%02i:%02i\n", time_str_tm->tm_hour, time_str_tm->tm_min, time_str_tm->tm_sec);
但tm
结构最后只有几秒......
有什么建议吗?
答案 0 :(得分:1)
您需要gettimeofday(2)
struct timeval time_now;
gettimeofday(&time_now, NULL);
time_str_tm = gmtime(&time_now.tv_sec);
printf("\n%02i:%02i:%02i:%06i\n"
, time_str_tm->tm_hour
, time_str_tm->tm_min
, time_str_tm->tm_sec
, time_now.tv_usec);