最简单代码。
#include <sys/time.h>
#include <inttypes.h>
uint64_t getCurrentTimestamp()
{
struct timeval tv;
gettimeofday(&tv,NULL);
printf("%d raw microseconds:\n",tv.tv_usec);
uint64_t time_in_micros =( (uint64_t)1000 * (tv.tv_sec) )+ tv.tv_usec/1000;
printf("%" PRIu64 " real microseconds:\n",time_in_micros);
return time_in_micros;
}
#include <sys/time.h>
#include <inttypes.h>
uint64_t getCurrentTimestamp()
{
struct timeval tv;
gettimeofday(&tv,NULL);
printf("%d raw microseconds:\n",tv.tv_usec);
uint64_t time_in_micros =( (uint64_t)1000 * (tv.tv_sec) )+ tv.tv_usec/1000;
printf("%" PRIu64 " real microseconds:\n",time_in_micros);
return time_in_micros;
}