c/c++ linux下获取时间

#include<sys/time.h>
/*
struct timeval
  {
    __time_t tv_sec;		 Seconds.  秒位部分
    __suseconds_t tv_usec;	 Microseconds.  微秒位部分
  };
*/

void fn(){
    struct timeval now;
    gettimeofday(&now, NULL); //获取从1970年1月1日到现在的时间
    cout<<"当前的时间是"<<(long)now.tv_sec*1000 + (long)now.tv_usec/1000<<"毫秒"<<endl;
}

原文地址:https://www.cnblogs.com/ishen/p/12579177.html