This will give you the time in the format HH:MM:SS:mmm

Code:
timeval tp;
gettimeofday(&tp, 0);
time_t curtime = tp.tv_sec;
tm *t = localtime(&curtime);
printf("%02d:%02d:%02d:%03d\n", t->tm_hour, t->tm_min, t->tm_sec, tp.tv_usec/1000);