year_month_day

year_month_day (완전한 날짜)

연·월·일을 모두 담은 완전한 달력 날짜 타입이에요. <chrono> 헤더, C++20부터.

출처: cppreference

본문

std::chrono::year_month_day는 연도·월·일로 구성된 완전한 날짜예요.

class year_month_day;
  • year(), month(), day() 멤버 제공.
  • ok(): 유효한 실제 달력 날짜인지(윤년 포함) 확인.
  • operator/로 간단히 생성: 2023y / June / 15.
  • sys_days(시스템 시점)와의 변환(operator sys_days)과 차이 계산 지원.
using namespace std::chrono;
auto d = 2023y / June / 15;        // 2023-06-15
bool ok = d.ok();                  // true
auto ymd = year_month_day{sys_days{...}};   // sys에서 변환

원하는 날짜를 읽기 좋게 만들고, 날짜의 유효성 검사, 날짜 사이 차이(일수) 계산, sys 시점 변환으로 달력 연산을 할 때 쓰는 핵심 타입이에요.

더 알아보기 (Learn more)

cppreference