std::chrono::year_month_day_last
来自cppreference.com
工具库
日期和时间工具
时间点 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时长 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时钟 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
当天时刻 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
日历 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时区 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chrono I/O |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C 风格日期和时间 |
std::chrono::year_month_day_last
成员函数 | ||||
非成员函数 | ||||
辅助类 | ||||
在标头
<chrono>
定义
|
||
class
year_month_day_last;
|
(C++20 起) | |
类 year_month_day_last
表示特定年和月的最后一日。它是基于域的时间点,解析为 std::chrono::days,所受的限制是它只能表示月的最后一日。
它直接支持面向 std::chrono::years 和 std::chrono::months 的算术。到 std::chrono::sys_days 的隐式转换等效地允许面向 std::chrono::days 的算术。
year_month_day_last
是可平凡复制 (TriviallyCopyable)
的标准布局类型 (StandardLayoutType)
。
成员函数
构造 year_month_day_last 对象 (公开成员函数) |
|
以 months 和 years 为数量修改时间点 (公开成员函数) |
|
访问此对象的域 (公开成员函数) |
|
转换到 std::chrono::time_point (公开成员函数) |
|
检查此对象是否表示合法日期 (公开成员函数) |
非成员函数
(C++20)
|
比较二个 year_month_day_last 值 (函数) |
(C++20)
|
将 year_month_day_last 和一定数量的 years 或 months
相加或相减 (函数) |
(C++20)
|
输出 year_month_day_last 到流中 (函数模板) |
辅助类
year_month_day_last 的格式化支持 (类模板特化) |
|
std::chrono::year_month_day_last 的散列支持 (类模板特化) |
示例
运行此代码
#include <chrono> #include <iostream> int main() { const auto ymd = std::chrono::year_month_day { std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now()) }; const std::chrono::year_month_day_last ymdl { ymd.year(), ymd.month() / std::chrono::last }; std::cout << "当前月的最后一天(" << ymdl << ")是:" << std::chrono::year_month_day{ymdl}.day() << '\n'; // 'last' 对象可以用于任何可以合法使用 'day' 的地方: using namespace std::chrono; constexpr std::chrono::year_month_day_last ymdl1 = 2023y / February / last, ymdl2 = last / February / 2023y, ymdl3 = February / last / 2023y; static_assert(ymdl1 == ymdl2 and ymdl2 == ymdl3); }
可能的输出:
当前月的最后一天(2023/Aug/last)是:31
参阅
(C++20)
|
表示特定的 year 、 month 和 day (类) |