Time Duration Calculations

This lesson will explain which time duration operations are supported in C++.

The time durations support basic arithmetic operations, meaning you can multiply or divide a time duration by a number. Of course, you can compare time durations. I explicitly want to emphasize that all these calculations and comparisons respect the units.

With the C++14 standard, it gets even better; the C++14 standard supports the typical time literals.

Type Suffix Example
std::chrono::hours h 5h
std::chrono::minutes min 5min
std::chrono::seconds s 5s
std::chrono::milliseconds ms 5ms
std::chrono::microseconds us 5us
std::chrono::nanoseconds ns 5ns

How much time does my son Marius (17 years old) spend in a typical school day? I will answer the question in the following example and show the result in various time durations formats.

Get hands-on with 1200+ tech skills courses.