C/C++获取系统时间戳,精确到毫秒

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liyunlong41/article/details/76933575


    一年没写博客了,很是怀念以前刷题的日子啊~ 现在工作了,开始学技术了,把自己遇到的一些技术点写在博客上,便于以后翻阅。

    #include <stdio.h>    
    #include <sys/time.h>      //添加头文件
    int64_t getCurrentTime()      //直接调用这个函数就行了,返回值最好是int64_t,long long应该也可以
    {    
       struct timeval tv;    
       gettimeofday(&tv,NULL);    //该函数在sys/time.h头文件中
       return tv.tv_sec * 1000 + tv.tv_usec / 1000;    
    }    
        
    int main()    
    {    
        std::cout<<"nowTime: "<<getCurrentTime()<<"\n";    //如果想要到秒级别的,只要除以1000就行了
        return 0;    
    }  

   感觉自己现在好菜,希望自己能坚持住,把技术搞好。

猜你喜欢

转载自blog.csdn.net/liyunlong41/article/details/76933575
今日推荐