Calendar Dates
Explore the use of calendar date types in C++20's chrono library to understand year, month, day representations and how to create, validate, and display dates effectively. This lesson covers the key types like year_month_day, date literals, the cute syntax for date creation, and handling special calendar cases including leap years and weekdays.
We'll cover the following...
We'll cover the following...
A new type of the chrono extension in C++20 is a calendar date. C++20 supports various ways to create a calendar date and interact with them. First of all: What is a calendar date?
- A calendar date is a date that consists of a year, a month, and a day. Consequently, C++20 has a specific data type
std::chrono::year_month_day. C++20 has way more to offer. The following table should give you the first overview of calendar-date types before I show you various use-cases.
| Type | Description |
|---|---|
std::chrono::last_spec |
Indicates the last day or weekday of a month |
std::chrono::day |
Represents a day of a month |
std::chrono::month |
Represents a month of a year |
std::chrono::year |
Represents a year in the Gregorian calendar |
std::chrono::weekday |
Represents a day of the week in the Gregorian calendar |
std::chrono::weekday_indexed |
Represents the nth weekday of a month |
std::chrono::weekday_last |
Represents the last weekday of a month |