Expressing time intervals with chrono::duration
Working with times and dates is a common operation, regardless of the programming language. C++11 provides a flexible date and time library as part of the standard library that enables us to define time points and time intervals. This library, called chrono
, is a general-purpose utility library designed to work with a timer and clocks that can be different on different systems and, therefore, be precision-neutral. The library is available in the <chrono>
header in the std::chrono
namespace and defines and implements several components, as follows:
- Durations, which represent time intervals
- Time points, which present a duration of time since the epoch of a clock
- Clocks, which define an epoch (that is, start of time) and a tick
In this recipe, we will learn how to work with durations.
Getting ready
This recipe is not intended as a complete reference to the duration
class. It is recommended...