时间结构体
struct timeval
{
__time_t tv_sec; //Seconds.
__suseconds_t tv_usec; //Microseconds.
};
struct timespec {
time_t tv_sec; // seconds
long tv_nsec; // nanoseconds
};
struct tm {
int tm_sec; /* Seconds (0-60) */
int tm_min; /* Minutes (0-59) */
int tm_hour; /* Hours (0-23) */
int tm_mday; /* Day of the month (1-31) */
int tm_mon; /* Month (0-11) */
int tm_year; /* Year - 1900 */
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
int tm_isdst; /* Daylight saving time */
};
时间函数
gettimeofday函数
int gettimeofday(struct timeval*tv, struct timezone *tz);
gettimeofday()会把目前的时间用tv 结构体返回。tz可以设为NULL。函数执行成功后返回0,失败后返回-1,错误代码存于errno中。
clock_gettime函数
int clock_gettime(clockid_t clk_id, struct t