struct timeval和gettimeofday小记
2017-04-02 22:51
363 查看
struct timeval是一个时间结构体, 具体字段分别是秒和微秒, gettimeofday是具体获取时间的函数, 看个程序就明白了:
#include<stdio.h>
#include<sys/time.h>
int main()
{
struct timeval tv;
gettimeofday(&tv, NULL);
printf("second:%d\n", tv.tv_sec); // second 秒
printf("micro second:%d\n", tv.tv_usec); // micro second 微秒
return 0;
} 结果:
second:1491172737
micro second:693439
很简单, 就这样。
#include<stdio.h>
#include<sys/time.h>
int main()
{
struct timeval tv;
gettimeofday(&tv, NULL);
printf("second:%d\n", tv.tv_sec); // second 秒
printf("micro second:%d\n", tv.tv_usec); // micro second 微秒
return 0;
} 结果:
second:1491172737
micro second:693439
很简单, 就这样。
相关文章推荐
- struct timeval结构体 以及 gettimeofday()函数
- struct timeval结构体 以及 gettimeofday()函数
- struct timeval结构体 以及 gettimeofday()函数
- struct timeval结构体 以及 gettimeofday()函数
- linux系统中struct timeval结构体、struct timezone结构体以及gettimeofday函数
- struct timeval结构体 以及 gettimeofday()函数
- struct timeval和gettimeofday()用法
- struct timeval和gettimeofday()
- struct timeval结构体 以及 gettimeofday()函数
- [转]struct timeval结构体 以及 gettimeofday()函数
- gettimeofday(struct timeval *tv, struct timezone *tz)函数
- struct timeval结构体 以及 gettimeofday()函数
- 十七 struct timeval结构体 以及 gettimeofday()函数
- gettimeofday(struct timeval *tv, struct timezone *tz)函数
- struct timeval和gettimeofday()
- 有关struct timeval结构体 以及 gettimeofday()函数
- struct timeval结构体 以及 gettimeofday()函数
- struct timeval结构体 以及 gettimeofday()函数
- gettimeofday() -- 获取当前时间(保存在结构体timeval中)
- C语言获取微秒级的系统时间 gettimeofday timeval timeout