名稱空間
變體
操作

std::chrono::year_month::year, std::chrono::year_month::month

來自 cppreference.com
< cpp‎ | chrono‎ | year_month
 
 
 
 
constexpr std::chrono::year year() const noexcept;
(1) (C++20 起)
constexpr std::chrono::month month() const noexcept;
(2) (C++20 起)

檢索儲存在此 year_month 物件中的年份和月份值。

[編輯] 返回值

1) 返回儲存的 std::chrono::year 值。
2) 返回儲存的 std::chrono::month 值。

[編輯] 示例

#include <chrono>
#include <iostream>
 
int main()
{
    std::cout << std::boolalpha;
 
    constexpr auto ym{std::chrono::year(2021)/std::chrono::July};  
    std::cout << (ym.year() == std::chrono::year(2021)) << ' ';
    std::cout << (ym.month() == std::chrono::month(7)) << '\n';
}

輸出

true true