How to convert from seconds to nanoseconds in a timeval struct?

3.6k Views Asked by At

I want to convert my timeval struct from seconds to nanoseconds, what is the best algorithm to achieve this?

1

There are 1 best solutions below

0
jj_3684 On

I would suggest this:

uint64_t nanosec(struct timeval t) { /* Calculate nanoseconds in a timeval structure */ 
  return t.tv_sec * 1000000000 + t.tv_usec * 1000; 
}