std::chrono::year_month_weekday:: year, std::chrono::year_month_weekday:: month, std::chrono::year_month_weekday:: weekday, std::chrono::year_month_weekday:: index, std::chrono::year_month_weekday:: weekday_indexed
From cppreference.net
<
cpp
|
chrono
|
year month weekday
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::chrono::year_month_weekday
| Member functions | ||||
|
year_month_weekday::year
year_month_weekday::month
year_month_weekday::weekday
year_month_weekday::index
year_month_weekday::weekday_indexed
|
||||
| Nonmember functions | ||||
| Helper classes | ||||
|
constexpr
std::
chrono
::
year
year
(
)
const
noexcept
;
|
(1) | (自 C++20 起) |
|
constexpr
std::
chrono
::
month
month
(
)
const
noexcept
;
|
(2) | (自 C++20 起) |
|
constexpr
std::
chrono
::
weekday
weekday
(
)
const
noexcept
;
|
(3) | (自 C++20 起) |
|
constexpr
unsigned
index
(
)
const
noexcept
;
|
(4) | (自 C++20 起) |
|
constexpr
std::
chrono
::
weekday_indexed
weekday_indexed
(
)
const
noexcept
;
|
(5) | (自 C++20 起) |
获取存储在此
year_month_weekday
对象中的字段值。
返回值
1)
返回存储的
std::chrono::year
值。
2)
返回存储的
std::chrono::month
值。
3)
返回存储的
std::chrono::weekday
值。
4)
返回存储的星期索引。
5)
weekday
(
)
[
index
(
)
]
示例
运行此代码
#include <cassert> #include <chrono> int main() { constexpr auto ym{std::chrono::year(2021)/std::chrono::January}; constexpr auto wdi{std::chrono::Wednesday[1]}; auto ymwdi{ym/wdi}; const auto index{ymwdi.index() + 1}; auto weekday{ymwdi.weekday() + std::chrono::days(1)}; ymwdi = {ymwdi.year()/ymwdi.month()/weekday[index]}; // 2021年1月的第二个星期四 assert(std::chrono::year_month_day{ymwdi} == std::chrono::January/14/2021); }