gettimeofday(struct timeval *tv, struct timezone *tz)函数

时间:2022-06-29 04:15:36

gettimeofday(struct timeval *tv, struct timezone *tz)函数

功能:获取当前精确时间(Unix时间)

其中:

timeval为时间

truct timeval{
long tv_sec; // 秒数
long  tv_usec; // 微秒数
}

timezone为时区

#include<stdio.h>
#include<sys/time.h>
int main(){
struct timeval tv;
gettimeofday(&tv,NULL);
printf("%d,%d\n",tv.tv_sec,tv.tv_usec);
return 0;
}

gettimeofday(struct timeval *tv, struct timezone *tz)函数