打印日志的时候显示毫秒

Posted yuandaozhe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了打印日志的时候显示毫秒相关的知识,希望对你有一定的参考价值。

打印日志的时候需要细化到毫秒级别

time_t t = time(NULL);
    struct tm tm;
#if defined(_WIN32)
    localtime_s(&tm, &t);
#else
    tm = *localtime(&t);
#endif
    struct timeb msec;
    ftime(&msec);
    printf("%.2d/%.2d %.2d:%.2d:%.2d.%03d	%s
", tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, msec.millitm, "test string");

 

以上是关于打印日志的时候显示毫秒的主要内容,如果未能解决你的问题,请参考以下文章