#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <time.h>
int main (void)
{
long ms; // Milliseconds
struct timespec spec;
clock_gettime(CLOCK_REALTIME, &spec);
ms = spec.tv_sec*1e3 + spec.tv_nsec/1e6;
printf("sec=%ld, nsec=%ld, t=%ld\n", spec.tv_sec, spec.tv_nsec, ms);
return 0;
}
运行结果:
sec=1553072747, nsec=210361207, t=1553072747210
sec=1553072747, nsec=922195774, t=1553072747922
sec=1553072748, nsec=530646955, t=1553072748530
离线