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 that represent time intervals.
- Time points that present a duration of time since the epoch of a clock.
- Clocks that define an epoch (that is, start of time) and a tick.
In this recipe, we will see how to work with durations.