您好,如何使用我正在使用的 C++ 中的以下函数以宏秒打印时间,
time_t rawtime;
time(&rawtime);
std::cout<<"Cuuent TIme is :: "<< ctime(&rawtime)<< std::endl;
上面的代码只会给我小时、分钟和秒。我还需要微秒。 有什么建议如何获取微秒的时间吗?
最佳答案
我使用以下代码来获取 H、M、S、mS 时间:
char timeBuf [256];
struct timeval tv;
struct timezone tz;
struct tm *tm;
gettimeofday(&tv, &tz);
tm=localtime(&tv.tv_sec);
sprintf (timeBuf, "%02d:%02d:%02d:%03ld",tm->tm_hour, tm->tm_min, tm->tm_sec, (tv.tv_usec/1000) );
关于c++ - 如何使用 ctime() 函数打印以微秒为单位的时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7581223/