How can I get (some kind of a extremely precise) time stamp?
My application needs to get and store (accurate) server time, including hours, minutes, seconds and milliseconds.
How can I get this (extremely precise) time stamp?
How can I get (some kind of a extremely precise) time stamp?
My application needs to get and store (accurate) server time, including hours, minutes, seconds and milliseconds.
How can I get this (extremely precise) time stamp?
As you do not seem to need nanosecond precision, the correct and portable way of doing this is not to play with mach_absolute_time()
, but by using gettimeofday()
:
#include <sys/time.h>
…
struct timeval tv;
gettimeofday(&tv, NULL);
…
You can then access the seconds since 1970-01-01 00:00 UTC in tv.tv_sec
and the microseconds in tv.tv_usec
.