您的位置:首页 > 其它

gettimeofday

2015-09-12 14:21 417 查看
函数原型

#include <sys/time.h>
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv, const struct timezone *tz);
返回值 : 正确返回0  失败返回-1,并且设置对应的errno的值

函数描述

             gettimeofday与settimeofday分别可以用来获取和设置时间,时区信息。

             tv参数的结构: 头文件<sys/time.h>
struct timeval
{
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
}           timeval的字段类型通常为long类型
 

          tz参数的结构:         struct timezone
{
int tz_minuteswest;/* minutes west of Greenwich */
int tz_dsttime; /* type of DST correction */
};


           如果tv或者tz为NULL,对应的信息并不会被设置返回。
           另外tz参数在linux是被废弃的,引用linux man中的一段话:

The  use  of the timezone structure is obsolete; the tz argument should
normally be specified as NULL.  The tz_dsttime  field  has  never  been
used  under Linux; it has not been and will not be supported by libc or
glibc.  Each and every occurrence of this field in  the  kernel  source
(other  than  the declaration) is a bug.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: