通过获取当前时间毫秒

 c

#include    

struct timeval now;
gettimeofday( &now, nullptr );
int64_t nowMillisecond = ((int64_t)now.tv_sec)*1000;
nowMillisecond += (int64_t)(now.tv_usec)/1000;

c++

#include 
   
std::chrono::time_point tp = std::chrono::time_point_cast(std::chrono::system_clock::now());
auto tmp=std::chrono::duration_cast(tp.time_since_epoch());
std::time_t timestamp = tmp.count(); //从1970-01-01 00:00:00到当前时间点的时长
std::cout << "timestamp:" << timestamp << std::endl;//微妙数

 

你可能感兴趣的:(c/c++/c++11)