Calendar Dates

Learn how to create and display calendar dates.

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
std::chrono::month_day Represents a specific day of a specific month
std::chrono::month_day_last Represents the last day of a specific month
std::chrono::month_weekday Represents the nth weekday of a specific month
std::chrono::month_weekday_last Represents the last weekday of a specific month
std::chrono::year_month Represents a specific month of a specific year
std::chrono::year_month_day Represents a specific year, month, and day
std::chrono::year_month_day_last Represents the last day of a specific year and month
std::chrono::year_month_weekday Represents the nth weekday of a specific year and month
std::chrono::year_month_day_weekday_last Represents the last weekday of a specific years and month
std::chrono::operator / Creates a date of the Gregorian calendar

Let me start simple and create a few calendar dates.

Create calendar dates

The following program shows various ways to create calendar-related dates.

Get hands-on with 1200+ tech skills courses.