美文网首页
读取系统时间

读取系统时间

作者: 胤默思佚 | 来源:发表于2017-03-13 17:29 被阅读12次

获取当前的时间的秒数和微秒数本方法需要用到gettimeofday()函数,该函数需要引入的头文件是 sys/time.h 。

函数返回当前时间:

long int micros()
{
    struct timeval tv;
    gettimeofday(&tv,NULL);
    return(tv.tv_sec);//秒
    //return (tv.tv_sec*1000 + tv.tv_usec/1000);//毫秒
    //return(tv.tv_sec*1000000 + tv.tv_usec);//微秒
}

所用到的函数解析:

int gettimeofday (struct timeval * tv, struct timezone * tz)

struct timeval{ 
long tv_sec; //秒 
long tv_usec; //微秒 
}; 
struct timezone 
{ 
int tz_minuteswest; //和Greenwich 时间差了多少分钟 
int tz_dsttime; //日光节约时间的状态 
}; 

参考:http://blog.csdn.net/deyuzhi/article/details/51814934

相关文章

网友评论

      本文标题:读取系统时间

      本文链接:https://www.haomeiwen.com/subject/plkqnttx.html