官方微博
关注微信公众号 关注微信公众号

当前位置: 主页 > 新2备用网址 >

C++ 获取以后时间毫秒数(兼容windows和linux)

2019-01-23 12:24 - - 查看:
https://blog.csdn.net/sunxianliang1/article/details/52150365 ? #ifdef _WIN32 ?#include ?#include #else ?#include #endif ? unsigned long long GetCurrentTimeMsec() { #ifdef _WIN32 ? ?struct timeval tv; ? ?time_t clock; ? ?struct tm tm; ? ?SYS

  https://blog.csdn.net/sunxianliang1/article/details/52150365

  ?

  #ifdef _WIN32

   ?#include

   ?#include

  #else

   ?#include

  #endif

  ?

  unsigned long long GetCurrentTimeMsec()

  {

  #ifdef _WIN32

   ? ?struct timeval tv;

   ? ?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);

   ? ?tv.tv_sec=clock;

   ? ?tv.tv_usec=wtm.wMilliseconds * 1000;

   ? ?return ((unsigned long long)tv.tv_sec * 1000 + (unsigned long long)tv.tv_usec / 1000);

  #else

  ? ? ? ? struct timeval tv;

  ? ? ? ? gettimeofday(&tv,NULL);

  ? ? ? ? return ((unsigned long long)tv.tv_sec * 1000 + (unsigned long long)tv.tv_usec / 1000);

  #endif

  ? ? }

上一篇:上一篇:CTP体系团弄体投资者为什么没拥有拥有权限下单 下一篇:下一篇:没有了