struct timeval结构体 以及 gettimeofday()函数

来源:互联网 发布:手机温度测试软件 编辑:程序博客网 时间:2024/05/20 09:43
关于 struct timeval

struct timeval{    __time_t tv_sec;/*Seconds.*/    __suseconds_t tv_usec;/*Miceoseconds.*/};其中tv_sec是Epoch到创建结构体timeval的秒数,tv_usec为微秒数,也就是秒数后面的零头,下面做一个实验

#include<cstdio>#include<windows.h>./Sleep#include<sys/time.h>#include<iostream>using namespace std;int main(){    struct timeval tv;    for(int i=0; i<5; ++i)    {        gettimeofday(&tv,NULL);        printf("%d\t%d\n",tv.tv_usec,tv.tv_sec);        Sleep(1000);//线程休眠一秒    }    return 0;}




关于gettimeofday()函数:

gettimeofday()功能是得到当前时间和时区,分别写到tv和tz中,如果tz为NULL则不向tz写入。


阅读全文
0 0