Using calendar and time zone capabilities
C++20 introduces brand-new support for calendar and time zone operations to the standard. When we talk about calendar operations, this means operations in days, months, and years. They, together with the time zone notion, allow conversions of time between different time zones taking into account time zone adjustments such as daylight saving time.
Let’s define a date and print it with the help of the chrono
library:
using namespace std::chrono; year theYear{2023}; month theMonth{8}; day theDay{4}; std::cout << "Year: " << theYear; std::cout << ", Month: " << theMonth; std::cout << ", Day: " << theDay << '\n';
As you can see, the std::chrono
namespace provides year
, month
, and day
classes, which make it easy to work with dates. The benefit of these classes is that they provide strict type and boundary checks, some operators for summation and subtraction...