다음을 통해 공유


year_month_day_last 클래스

특정 연도 및 월의 마지막 날을 나타냅니다.

year_month_day_last 는 월 산술 및 연도 산술 연산을 지원하지만 일 산술 연산은 지원하지 않습니다. 일 지향 산술 연산을 수행하려면 다음으로 sys_days변환 year_month_day_last 합니다.

구문

class year_month_day_last; // C++20

멤버

속성 설명
생성자 a 생성 year_month_day_last
day 월/연도의 마지막 날을 가져옵니다.
month 월을 가져옵니다.
month_day_last year_month_day_last저장된 month_day_last 값을 가져옵니다.
ok 값과 month 값이 year 유효한 범위에 있는지 확인합니다.
operator+= year_month_day_last월 또는 연도를 추가합니다.
operator-= 에서 year_month_day_last월 또는 연도를 뺍니다.
operator local_days Epoch에서 sys_daysyear_month_day_last 날짜까지의 일 수를 다음과 같이 local_days가져옵니다.
operator sys_days Epoch에서 sys_daysyear_month_day_last 날짜까지의 일 수를 다음과 같이 sys_days가져옵니다.
year 연도를 가져옵니다.

비멤버

이름 설명
operator+ 월 또는 연도를 추가합니다.
operator- 월 또는 연도를 뺍니다.
operator== year_month_day_last 값이 같은지 여부를 확인합니다.
operator<=> year_month_day_last 값을 비교합니다. >, >=, <=, <, != 연산자는 컴파일러에 의해 합성됩니다.
operator<< 스트림에 출력 year_month_day_last 합니다.

요구 사항

헤더:<chrono> (C++20 이후)

네임스페이스:std::chrono

컴파일러 옵션:/std:c++latest

생성자

지정된 월 및 연도에 대한 a year_month_day_last 를 생성합니다.

constexpr year_month_day_last(const year& y, const month_day_last& mdl) noexcept;

매개 변수

mdl 해당 월 값 month_day_last 은 생성된 year_month_day_last에 저장됩니다.

y
값은 year 생성된 값에 저장됩니다 year_month_day_last.

설명

날짜를 지정하는 데 사용되는 C++20 구문에 대한 자세한 내용은 operator/

예: year_month_day_last 만들기

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

using namespace std::chrono;

int main()
{
    year_month_day_last ymdl{ April / last / 1975 };
    std::cout << ymdl;

    return 0;
}
1975/Apr/last

day

true경우 ok() 연도의 마지막 날을 나타내는 일, 이 year_month_day_last월이 나타내는 월을 반환합니다.

constexpr day day() const noexcept;

반환 값

true경우 ok() 연도의 마지막 날과 월을 나타내는 *this값을 반환 day 합니다. 그렇지 않으면 반환 값이 지정되지 않습니다.

local_days

year_month_day_last , 일 및 연도를 일 수로 가져옵니다.

constexpr explicit operator local_days() const noexcept;

반환 값

local_days{sys_days{*this}.time_since_epoch()}

예시

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

using namespace std::chrono;

int main()
{
    year_month_day_last ymdl{ June / last / 2021 };
    auto ld = local_days(ymdl);
    std::cout << ld.time_since_epoch();

    return 0;
}
18808d

month

저장된 월 값을 가져옵니다.

constexpr month month() const noexcept;

반환 값

month 값입니다.

month_day_last

year_month_day_lastmonth_day_last 저장된 값을 가져옵니다.

constexpr month_day_last month_day_last() const noexcept;

반환 값

month_day_lastyear_month_day_last값에 저장된 값입니다.

operator sys_days

시스템 시계에 대한 Epoch에서 일 수로 이 year_month_day_last 월, 일 및 연도를 가져옵니다.

constexpr explicit operator sys_days() const noexcept;

반환 값

sys_days{this->year()/this->month()/this->day()}를 반환합니다.

예시

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

using namespace std::chrono;

int main()
{
    year_month_day_last ymdl{ June / last / 2021 };
    auto sd = sys_days(ymdl);
    std::cout << sd.time_since_epoch();

    return 0;
}
18808d

year

연도를 가져옵니다.

constexpr year year() const noexcept;

반환 값

year.

ok

이 위치에 저장된 값과 month_day_last 값이 year_month_day_last 모두 유효한 범위에 있는지 year 확인합니다.

constexpr bool ok() const noexcept;

반환 값

true 이 값에 year 저장된 값과 month_day_last 값이 year_month_day_last 모두 유효한 범위에 있으면 입니다. 그렇지 않으면 false입니다.

operator+=

year_month_day_last월 또는 연도를 추가합니다.

1) constexpr year_month_day_last& operator+=(const months& m) noexcept;
2) constexpr year_month_day_last& operator+=(const years& y) noexcept;

매개 변수

m
추가할 월 수입니다.

y
추가할 연도 수입니다.

반환 값

*this- 추가 결과를 반영합니다.

예: operator+=

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

using namespace std::chrono;

int main()
{
    year_month_day_last ymdl{ April / last / 1975 };

    std::cout << ymdl << '\n';

    ymdl += months{1};
    ymdl += years{1};

    std::cout << ymdl;
    
    return 0;
}
1975/Apr/last
1976/May/last

operator-=

에서 year_month_day_last월 또는 연도를 뺍니다.

1) constexpr year_month_day_last& operator-=(const months& m) noexcept;
2) constexpr year_month_day_last& operator-=(const years& y) noexcept;

매개 변수

m
뺄 월 수입니다.

y
뺄 연도 수입니다.

반환 값

*this- 빼기의 결과를 반영합니다.

예: operator-=

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

using namespace std::chrono;

int main()
{
    year_month_day_last ymdl{ April / last / 1975 };

    std::cout << ymdl << '\n';

    ymdl -= months{1};
    ymdl -= years{1};

    std::cout << ymdl;
    
    return 0;
}
1975/Apr/last
1974/Mar/last

참고 항목

<chrono>
year
year_month
year_month_day
year_month_weekday
year_month_weekday_last
operator/
헤더 파일 참조