打印日志的时候显示毫秒

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

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\t%s\n", tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, msec.millitm, "test string");

 

posted on 2019-10-22 14:30  弘道者  阅读(1399)  评论(0编辑  收藏  举报