首页 > 其他分享 >the new 2023,the elapsed time drives me more mature

the new 2023,the elapsed time drives me more mature

时间:2023-01-01 17:23:57浏览次数:38  
标签:me count chrono since drives epoch 2023 time now

//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

 

标签:me,count,chrono,since,drives,epoch,2023,time,now
From: https://www.cnblogs.com/Fred1987/p/17018290.html

相关文章