命名空间
变体
操作

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

来自 cppreference.cn
< 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