How to get the current time in milliseconds from C in Linux?

前端 未结 7 931
不知归路
不知归路 2020-11-30 19:09

How do I get the current time on Linux in milliseconds?

7条回答
  •  长情又很酷
    2020-11-30 19:45

    You have to do something like this:

    struct timeval  tv;
    gettimeofday(&tv, NULL);
    
    double time_in_mill = 
             (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ; // convert tv_sec & tv_usec to millisecond
    

提交回复
热议问题