最終更新日時(UTC):
が更新

履歴 編集

function
<chrono>

std::chrono::weekday::operator[](C++20)

constexpr weekday_indexed
  operator[](unsigned int index) const noexcept; // (1) C++20

constexpr weekday_last
  operator[](last_spec) const noexcept;          // (2) C++20

概要

月のN回目の指定した曜日を取得する。

  • (1) : 月のN回目の指定した曜日を取得する
  • (2) : 月の最後の指定した曜日を取得する

戻り値

例外

投げない

#include <iostream>
#include <chrono>

using namespace std::chrono;

int main()
{
  {
    // 2019年11月の3回目の日曜日が何日か
    year_month_weekday base_date = 2019y/November/Sunday[3];
    year_month_day date{sys_days{base_date}}; // 年/月/日に変換
    std::cout << static_cast<unsigned int>(date.day()) << std::endl; // 日を取得
  }
  {
    // 2019年11月の最後の日曜日が何日か
    year_month_weekday_last base_date = 2019y/November/Sunday[last];
    year_month_day date{sys_days{base_date}};
    std::cout << static_cast<unsigned int>(date.day()) << std::endl;
  }
}

出力

17
24

バージョン

言語

  • C++20

処理系

  • Clang: 8.0
  • GCC: (9.2時点で実装なし)
  • Visual C++: (2019 Update 3時点で実装なし)