天天看點

擷取時間戳(毫秒級别)

第一種:

#include <chrono>
std::string getCurrentTime()
{
    auto timeNow = chrono::duration_cast<chrono::milliseconds>( chrono::system_clock::now().time_since_epoch() );
    char bufTime[16] { 0 };
    sprintf( bufTime, "%lld", timeNow.count() );
    std::string ts = bufTime;
    return ts;
}
           

第二種:

int64_t Base_CLinkClient::getCurrentTime()
{
   struct timeval tv;
   gettimeofday(&tv,NULL);
   LOG_DEBUG("timeStamp:%lld,%ld", tv.tv_sec * 1000 + tv.tv_usec / 1000,time(NULL));
   return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
           

繼續閱讀