std::chrono::year_month:: year, std::chrono::year_month:: month
From cppreference.net
<
cpp
|
chrono
|
year month
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::chrono::year_month
| Member functions | ||||
|
year_month::year
year_month::month
|
||||
| Nonmember functions | ||||
| Helper classes | ||||
|
(C++26)
|
|
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