std::chrono::year::operator int
From cppreference.com
| constexpr explicit operator int() const noexcept; |
(C++20以降) | |
*thisに格納されている年値を返します。
[編集] 戻り値
*thisに格納されている年値。
[編集] 例
このコードを実行
#include <chrono> #include <iostream> using namespace std::chrono; int main() { constexpr std::chrono::year y{2020}; std::cout << "The year is: " << static_cast<int>(y) << '\n'; const year_month_day ymd{floor<days>(system_clock::now())}; const std::chrono::year this_year{ymd.year()}; std::cout << "This year is: " << int(this_year) << '\n'; }
実行結果の例
The year is: 2020 This year is: 2023