Std::chrono How to use this C++ time tool

Evidently std::chrono is the modern time-keeping tool of choice for C++. I’ve had problems using it to measure time beginning at a certain program condition and triggering an event when a predefined interval has elapsed.

To further confuse me, Visual C++ seems to be returning a duration in nanoseconds. It is more convenient for me to work in milliseconds or maybe microseconds.

Anybody know of a gentle (but not too gentle) introduction or discussion of chrono, hopefully with numerous examples.

Many thanks!

Hi! Did you look at ? There it is suggested to look at examples at and

Not numerous examples, but it’s something :slight_smile:

hamoid: Thanks for the links to cplusplus pages. I think I glanced at ~/chrono once, got a little overwhelmed with terse presentation and so failed to click on to ~/system_clock and ~/steady_clock. Looking at these pages helps clear up simple usage I’m looking for.

I need to dig a little deeper into use of ratio and/or duration_cast to get desired units of milliseconds. Also am mystified about Visual Studio C++ seeming default to nanoseconds when calling the .now() method.

Internet search also turned up this tutorial:
I have not yet fully watched (nor understood) the presentation but will carry on and keep calm.

1 Like