欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

inux下gettimeofday函数windows替换方法(详解)

程序员文章站 2023-11-03 14:29:34
实例如下: #include #ifdef win32 # include #else...

实例如下:

#include <time.h>
#ifdef win32
#  include <windows.h>
#else
#  include <sys/time.h>
#endif
#ifdef win32
int
gettimeofday(struct timeval *tp, void *tzp)
{
  time_t clock;
  struct tm tm;
  systemtime wtm;
  getlocaltime(&wtm);
  tm.tm_year   = wtm.wyear - 1900;
  tm.tm_mon   = wtm.wmonth - 1;
  tm.tm_mday   = wtm.wday;
  tm.tm_hour   = wtm.whour;
  tm.tm_min   = wtm.wminute;
  tm.tm_sec   = wtm.wsecond;
  tm. tm_isdst  = -1;
  clock = mktime(&tm);
  tp->tv_sec = clock;
  tp->tv_usec = wtm.wmilliseconds * 1000;
  return (0);
}
#endif

以上就是小编为大家带来的inux下gettimeofday函数windows替换方法(详解)全部内容了,希望大家多多支持~