您好,欢迎来到华拓科技网。
搜索
您的当前位置:首页C++ 获取时间

C++ 获取时间

来源:华拓科技网

C++ 两种获取时间的方式

// 获取微秒
long GetCurrentMicroseconds(){
    timeval time;
    gettimeofday(&time,nullptr);
    return (time.tv_sec * 1000000 + time.tv_usec);
}

如果需要毫秒,则 return (time.tv_sec * 1000 + time.tv_usec/1000)

  1. 使用 #include 下面的 chrono库
    // 获取微秒
int_t CurrentTimeMillis(){
    auto now = chrono::system_clock::now();
    return chrono::duration_cast<chrono::microseconds>(now.time_since_epoch()).count();
}

如果需要的是毫秒,则 return chrono::duration_cast<:milliseconds>(now.time_since_epoch()).count();

转载于:https://www.cnblogs.com/daihanlong/p/8663238.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo6.cn 版权所有 赣ICP备2024042791号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务