timeval 结构体源码,gettimeofday() 的第一个参数
#ifndef __timeval_defined
#define __timeval_defined 1
#include <bits/types.h>
/* A time value that is accurate to the nearest
microsecond but also has a range of years. */
struct timeval
{
__time_t tv_sec; /* Seconds. */
__suseconds_t tv_usec; /* Microseconds. 1000000 微秒 = 1秒 */
};
#endif
tv_sec 代表多少秒
tv_usec 代表多少微秒 1000000 微秒 = 1秒
使用gettimeofday()来获取时间(1970年1月1日到现在的时间)
#include <sys/time.h>
int gettimeofday(struct timeval*tv, struct timezone *tz);
其参数tv是保存获取时间结果的结构体, 参数tz用于保存时区结果. timezone 参数若不使用则传入NULL即可。
timezone 结构体如下:
struct timezone{
int tz_minuteswest;/*格林威治时间往西方的时差*/
int tz_dsttime;/*DST 时间的修正方式*/
}