22Date and Time Utilities

This chapter discusses the time-related functionality provided by the C++ Standard Library, known collectively as the chrono library. It is a collection of classes and functions to work with time and dates. The library consists of the following components:

  • Durations
  • Clocks
  • Time points
  • Dates
  • Time zones

Everything is defined in <chrono> in the std::chrono namespace. However, before we can start the discussion of each of these chrono library components, we need a small digression to look at the compile-time rational number support available in C++, as this is heavily used by the chrono library.

COMPILE-TIME RATIONAL NUMBERS

The Ratio library allows you to exactly represent any finite rational number that you can use at compile time. Everything is defined in <ratio> and is in the std namespace. The numerator and denominator of a rational number are represented as compile-time constants of type std::intmax_t, which is a signed integer type with the maximum width supported by a compiler. Because of the compile-time nature of these ...

Get Professional C++, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.