一:所需文件:
#include <time.h>
#include <sys/time.h>
二:结构体说明
struct timeval
{
__time_t tv_sec; /* Seconds. */
__suseconds_t tv_usec; /* Microseconds. */
};
三:使用说明:
tv_sec为Epoch到创建struct timeval时的秒数,tv_usec为微秒数,
四:事例:
#include <sys/time.h>
#include <stdio.h>
int
main(void)
{
int i;
struct timeval tv;
for(i = 0; i < 4; i++){
gettimeofday(&tv, NULL);
printf("%d\t%d\n", tv.tv_usec, tv.tv_sec);
sleep(1);
}
return 0;
}
执行结果: