tags:

views:

124

answers:

4

How do I get the current time on Linux in milliseconds? This is for the purpose of testing.

label1 .....

label2.

A: 

man gettimeofday

asveikau
+5  A: 

Use gettimeofday() to get the time in seconds and microseconds. Combining and rounding to milliseconds is left as an exercise.

Donal Fellows
+1  A: 

If you're looking for something to type into your command line, then Date +%H:%M:%S.%N will give you the time with nanoseconds.

Kristian Antonsen
A: 

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
yadab