month_day class

Represents a specific day of a specific month. The year isn't specified.

Syntax

class month_day; // C++20

Members

Name Description
Constructors Construct a month_day.
day Return the day value.
month Return the month value.
ok Check if the month_day is valid.

Non-members

Name Description
from_stream Parse a month_day from the given stream using the specified format.
operator== Determine whether two months are equal.
operator<=> Compare this month against another month. The >, >=, <=, <, != operators are synthesized by the compiler.
operator<< Output a month_day to the given stream.

Requirements

Header: <chrono> (since C++20)

Namespace: std::chrono

Compiler Option: /std:c++latest

Constructors

Construct a month_day.

1) month_day() = default;
2) constexpr month_day(const month& m, const day& d) noexcept;

Parameters

d
Construct a month_day with a day value of d.

m
Construct a month_day with a month value of m.

Remarks

1) The default constructor doesn't initialize the month or day values.
2) Construct a month_day with the month value initialized to m and the day value initialized to d.

For information about C++20 syntax to specify dates, see operator/

Example: Create a month_day

// compile using: /std:c++latest
#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
    month_day md(30d/July);
    month_day md2 = July/30; // another way to construct a month_day

    std::cout << md << '\n' << md2;
    return 0;
}
Jul/30
Jul/30

day

Return the day value.

constexpr day day() const noexcept;

Return value

The day value.

month

Return the month value.

constexpr month month() const noexcept;

Return value

The month value.

ok

Check if the value stored in this month_day is valid.

constexpr bool ok() const noexcept;

Return value

true if the month_day value is valid. Otherwise, false.
A month_day is valid if the month is valid and the day is less than or equal to the number of days in that month. February has 29 days.

See also

<chrono>
month class
month_day class
month_day_last class
month_weekday class
month_weekday_last class
operator/