命名空间
变体
操作

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

来自 cppreference.cn
< cpp‎ | chrono‎ | year month
 
 
 
 
constexpr std::chrono::year year() const noexcept;
(1) (since C++20)
constexpr std::chrono::month month() const noexcept;
(2) (since C++20)

检索存储在此 year_month 对象中的年和月值。

[edit] 返回值

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

[edit] 示例

#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