How do I get a microseconds timestamp in C?
I'm trying to do:
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_usec;
But this returns some nonsense value that if I get two timestamps, the second one can be smaller or bigger than the first (second one should always be bigger). Would it be possible to convert the magic integer returned by gettimeofday to a normal number which can actually be worked with?
You have two choices for getting a microsecond timestamp. The first (and best) choice, is to use the
timeval
type directly:The second, and for me less desirable, choice is to build a uint64_t out of a
timeval
: