函数原型

  1. #include <sys/time.h>
  2. int gettimeofday(struct timeval *tv, struct timezone *tz);
  3. int settimeofday(const struct timeval *tv, const struct timezone *tz);

参数

结构体timeval

  1. struct timeval
  2. {
  3. long tv_sec;/*秒数*/
  4. long tv_usec;/*微秒数*/
  5. };

当前时间会返回给这个结构体指针tv。

结构体timezone

可以设为NULL。

返回值

  • 0 :成功
  • -1:失败