std::chrono::weekday::operator[]
来自cppreference.com
工具库
日期和时间工具
时间点 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时长 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时钟 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
当天时刻 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
日历 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
时区 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
chrono
I/O
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++20)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
C 风格日期和时间 |
std::chrono::weekday
成员函数 | ||||
weekday::operator[]
|
||||
非成员函数 | ||||
辅助类 | ||||
(C++26)
|
constexpr
std::chrono::weekday_indexed
operator[](unsigned
index)
const
noexcept;
|
(1) | (C++20 起) |
constexpr
std::chrono::weekday_last
operator[](std::chrono::last_spec)
const
noexcept;
|
(2) | (C++20 起) |
1) 从
*this
和
index
构造 weekday_indexed
。结果表示在某个待指定月份中的第
index
个星期之日。若 index
不在范围 [1, 5] 中或若 !ok() ,则结果中保有的值未指定。
2) 从
*this
构造
weekday_last
。结果表示某个待指定月份中的最后一个星期之日。返回值
1) std::chrono::weekday_indexed(*this, index)
2) std::chrono::weekday_last(*this)
示例
运行此代码
#include <chrono> #include <iostream> int main() { using namespace std::chrono; // 2019 年十月中的第二个星期二 std::cout << year_month_day{ Tuesday[2] / October / 2019y } << '\n' // 2019 年十月中的最后一个星期二 << year_month_day{ Tuesday[last] / October / 2019y } << '\n'; }
输出:
2019-10-08 2019-10-29