std::chrono::weekday_last::weekday_last
来自 cppreference.com
< cpp | chrono | weekday last
constexpr explicit weekday_last( const std::chrono::weekday& wd ) noexcept; |
(自 C++20 起) | |
构造一个存储 weekday wd 的 weekday_last
对象。
[编辑] 注释
构造 weekday_last
的更方便方法是使用 weekday
的 operator[],即 wd[std::chrono::last].
[编辑] 示例
运行此代码
#include <chrono> #include <iostream> using namespace std::chrono; int main() { const year_month_day ymd{floor<days>(system_clock::now())}; const weekday_last wdl{Sunday[last]}; // A last Sunday of a month const year_month_day last_sun{ymd.year() / ymd.month() / wdl}; std::cout << "The last Sunday of current month falls on " << (int)last_sun.year() << '/' << (unsigned)last_sun.month() << '/' << (unsigned)last_sun.day() << '\n'; }
可能的输出
The last Sunday of current month falls on 2021/9/26