当前位置: 移动技术网 > 网络运营>服务器>Linux > inux下gettimeofday函数windows替换方法(详解)

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

2019年04月26日  | 移动技术网网络运营  | 我要评论

实例如下:

#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替换方法(详解)全部内容了,希望大家多多支持移动技术网~

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网