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;
}

posted @ 2020-03-27 08:55  woder  阅读(1696)  评论(0编辑  收藏  举报