得到毫秒级别的时间戳

 test.cpp

#include 
#include     
#include 
#include 
using namespace std;
int64_t getCurrentTime()
{    
   struct timeval tv;    
   gettimeofday(&tv,NULL);  //该函数在sys/time.h头文件中
   return tv.tv_sec * 1000 + tv.tv_usec / 1000;    
}    
    
int main()    
{    
    int64_t time;
    time = getCurrentTime();
    cout<<"nowTime: "<
g++ -c test.cpp
g++ -o test test.o

./test
nowTime: 1565870866080

 

你可能感兴趣的:(C&C++)