How to print time in format: 2009‐08‐10 18:17:54.811

前端 未结 7 2005
旧时难觅i
旧时难觅i 2020-11-27 12:24

What\'s the best method to print out time in C in the format 2009‐08‐10 
18:17:54.811?

相关标签:
7条回答
  • 2020-11-27 12:58

    trick:

        int time_len = 0, n;
        struct tm *tm_info;
        struct timeval tv;
    
        gettimeofday(&tv, NULL);
        tm_info = localtime(&tv.tv_sec);
        time_len+=strftime(log_buff, sizeof log_buff, "%y%m%d %H:%M:%S", tm_info);
        time_len+=snprintf(log_buff+time_len,sizeof log_buff-time_len,".%03ld ",tv.tv_usec/1000);
    
    0 讨论(0)
提交回复
热议问题