时间boost

#include <time.h>

#include<sys/timeb.h>

#ifdef WIN32

#include<Windows.h>

#else

#include<stdint.h>

#include<sys/time.h>

#endif

 

#include"boost/chrono.hpp"

#include"boost/date_time.hpp"

__inline int64_t getMonotonicMesc(){

  #ifdef WIN32

  uint64_t n100ns;

  QueryUnbiasedInterruptTime(&n100ns);

  return n100ns/10000;

#else

  struct timespec ts;

  clock_gettime(CLOCK_MONOTONIC,&ts);

  return (int64_t)((int64_t)ts.tv_sec*1000+(int64_t)ts.tv_nsec/1000000);

#endif  

}

 

__inline int64_t getUTCTimeSec()

{

  boost::chrono::time_point<boost::chrono::system_clock,boost::chrono::seconds> curTime = boost::chrono::time_point_cast<boost::chrono::seconds>(boost::chrono::system_clock::now());

  return curTime.time_since_epoch().count();

}

 

__inline int64_t getUTCTimeMSec()

{

  boost::chrono::time_point<boost::chrono::system_clock,boost::chrono::milliseconds> curTime = boost::chrono::time_point_cast<boost::chrono::milliseconds>(boost::chrono::system_clock::now());

  return curTime.time_since_epoch().count();

}

posted on 2021-02-23 17:47  码农er  阅读(95)  评论(0编辑  收藏  举报