Linux C get the time of now:year-month-hour-minute-second-millisecond

struct timeval tv;
char buf[64];
gettimeofday(&tv, NULL);
strftime(buf, sizeof(buf)-1, "%Y-%m-%d %H:%M:%S", localtime(&tv.tv_sec));
printf("%s.%03d\n", buf, (int)(tv.tv_usec / 1000));
long last_time;
struct timeval tv;
gettimeofday(&tv, NULL);
last_time = tv.tv_sec * 1000+ tv.tv_usec/1000;
///
gettimeofday(&tv, NULL);
loge(tag, "interval=%ld", (tv.tv_sec * 1000+ tv.tv_usec/1000 - last_time));

猜你喜欢

转载自blog.csdn.net/hhbgk/article/details/79657749
今日推荐