C++ chrono system time in milliseconds, time operations

前端 未结 1 383
忘掉有多难
忘掉有多难 2020-12-04 09:58

I\'ve got a small problem caused by insufficient documentation of C++11.

I\'d like to obtain a time since epoch in milliseconds, or nanoseconds or seconds and then I

相关标签:
1条回答
  • 2020-12-04 10:31

    You can do now.time_since_epoch() to get a duration representing the time since the epoch, with the clock's resolution. To convert to milliseconds use duration_cast:

    auto duration = now.time_since_epoch();
    auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
    
    0 讨论(0)
提交回复
热议问题