std::chrono::year_month::year, std::chrono::year_month::month
来自cppreference.com
< cpp | chrono | year month
工具库
日期和时间工具
时间点 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时长 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时钟 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
当天时刻 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
日历 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时区 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chrono I/O |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C 风格日期和时间 |
std::chrono::year_month
成员函数 | ||||
year_month::yearyear_month::month
|
||||
非成员函数 | ||||
辅助类 | ||||
(C++26)
|
constexpr
std::chrono::year year() const noexcept;
|
(1) | (C++20 起) |
constexpr
std::chrono::month month() const noexcept;
|
(2) | (C++20 起) |
取得存储于此 year_month
对象的 year
和 month
值。
返回值
1) 返回存储的 std::chrono::year 值。
2) 返回存储的 std::chrono::month
值。
示例
运行此代码
#include <iostream> #include <chrono> 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