How to get duration, as int milli’s and float seconds from ?

Is this what you’re looking for? #include <chrono> #include <iostream> int main() { typedef std::chrono::high_resolution_clock Time; typedef std::chrono::milliseconds ms; typedef std::chrono::duration<float> fsec; auto t0 = Time::now(); auto t1 = Time::now(); fsec fs = t1 – t0; ms d = std::chrono::duration_cast<ms>(fs); std::cout << fs.count() << “s\n”; std::cout << d.count() << “ms\n”; } which for me prints … Read more

Converting steady_clock::time_point to time_t

Assuming you need the steady behavior for internal calculations, and not for display, here’s a function you can use to convert to time_t for display. using std::chrono::steady_clock; using std::chrono::system_clock; time_t steady_clock_to_time_t( steady_clock::time_point t ) { return system_clock::to_time_t(system_clock::now() + duration_cast<system_clock::duration>(t – steady_clock::now())); } If you need steady behavior for logging, you’d want to get one ( … Read more

How to get the precision of high_resolution_clock?

The minimum representable duration is high_resolution_clock::period::num / high_resolution_clock::period::den seconds. You can print it like this: std::cout << (double) std::chrono::high_resolution_clock::period::num / std::chrono::high_resolution_clock::period::den; Why is this? A clock’s ::period member is defined as “The tick period of the clock in seconds.” It is a specialization of std::ratio which is a template to represent ratios at compile-time. It … Read more

When is std::chrono epoch?

It is a function of both the specific clock the time_point refers to, and the implementation of that clock. The standard specifies three different clocks: system_clock steady_clock high_resolution_clock And the standard does not specify the epoch for any of these clocks. Programmers (you) can also author their own clocks, which may or may not specify … Read more