How do I get the current time on Linux in milliseconds?
This version need not math library and checked the return value of clock_gettime().
#include
#include
#include
/**
* @return milliseconds
*/
uint64_t get_now_time() {
struct timespec spec;
if (clock_gettime(1, &spec) == -1) { /* 1 is CLOCK_MONOTONIC */
abort();
}
return spec.tv_sec * 1000 + spec.tv_nsec / 1e6;
}