time函数解析

1.函数time_t time(time_t *t);
typedef time_t unsigned long;
time(0), time(NULL) 返回从1970.1.1 0:0:0(time_t(0))UTC时间格林威治时间至今所经过的时间秒数。
两次如果调用time()函数的时间间隔小于1秒,返回值相同。
这里写图片描述
unsigned long time1 = (unsigned long)time(0);
sleep(1);
unsigned long time2 = (unsigned long)time(NULL);

2.函数int gettimeofday(struct timeval*tv,struct timezone *tz ) 参看APUE
tv , tz
struct timeval{
long_t tv_sec; //s
long tv_usec; //10-6 s
}
struct timespec{
time_t tv_sec; //s
long tv_nsec; //10-9s
}

你可能感兴趣的:(时间管理)