the new 2023,the elapsed time drives me more mature

//model/util.cpp

void util::time_demo()
{
    static uint64_t num=0;
    chrono::time_point<chrono::high_resolution_clock> now = chrono::high_resolution_clock::now();
    // cout << "nanos " << chrono::duration_cast<chrono::nanoseconds>(now.time_since_epoch()).count()
    //      << ",micros " << chrono::duration_cast<chrono::microseconds>(now.time_since_epoch()).count()
    //      << ",mills " << chrono::duration_cast<chrono::milliseconds>(now.time_since_epoch()).count()
    //      << ",seconds " << chrono::duration_cast<chrono::seconds>(now.time_since_epoch()).count() << endl;
    chrono::milliseconds mills = chrono::duration_cast<chrono::milliseconds>(now.time_since_epoch());
    chrono::seconds seconds = chrono::duration_cast<chrono::seconds>(now.time_since_epoch());
    uint64_t millsValue = mills.count() - seconds.count() * 1000;
    time_t rawTime = chrono::high_resolution_clock::to_time_t(now);
    struct tm tmInfo = *std::localtime(&rawTime);
    stringstream ss;
    ss << std::put_time(&tmInfo, "%Y%m%d%H%M%S") << std::setfill('0') << std::setw(3) << millsValue;
    string dtvalue = ss.str();
    ss = stringstream(std::string());
    cout<< dtvalue << endl;
}

void util::print_time()
{
    while (1)
    {
        time_demo();
        usleep(100000);
    }
}

//main.cpp
#include "model/util.h"

void print_time_demo()
{
util ul;
ul.print_time();
}
 

int main(int args,char **argv)
{
print_time_demo();
}
 

 

Compile

g++ -g -std=c++2a -I. *.cpp ./model/*.cpp -o h1 -luuid -lpthread -ljsoncpp

 

Run

./h1

the new 2023,the elapsed time drives me more mature

 

原文链接: https://www.cnblogs.com/Fred1987/p/17018290.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    the new 2023,the elapsed time drives me more mature

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/401170

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年4月19日 上午9:09
下一篇 2023年4月19日 上午9:09

相关推荐