std::chrono::year_month_weekday::operator sys_days, std::chrono::year_month_weekday::operator local_days
Von cppreference.com
< cpp | chrono | year month weekday
| constexpr operator std::chrono::sys_days() const noexcept; |
(1) | (seit C++20) |
| constexpr explicit operator std::chrono::local_days() const noexcept; |
(2) | (seit C++20) |
Konvertiert *this in einen std::chrono::time_point, der dasselbe Datum wie dieses year_month_weekday repräsentiert.
1) Wenn year().ok() && month().ok() && weekday().ok()
- Wenn index() == 0, wird eine
sys_dayszurückgegeben, die das Datum 7 Tage vor dem erstenweekday()des Jahres und Monats repräsentiert. - Andernfalls wird eine
sys_dayszurückgegeben, die das Datum (index() - 1) * 7 Tage nach dem ersten weekday() des Jahres und Monats repräsentiert.
- Wenn index() == 0, wird eine
Andernfalls ist der zurückgegebene Wert undefiniert.
2) Wie (1), aber gibt
local_days anstelle von sys_days zurück. Äquivalent zu local_days(sys_days(*this).time_since_epoch()).[bearbeiten] Beispiel
Führen Sie diesen Code aus
#include <chrono> #include <iostream> using namespace std::chrono; int main() { constexpr auto ymwd{Tuesday[2]/11/2021}; std::cout << ymwd << '\n'; // convert from field-based to serial-based to add hours constexpr auto sd = sys_days{ymwd} + 24h; std::cout << sd << '\n'; constexpr auto ymd = floor<days>(sd); static_assert(ymd == November/10/2021); }
Ausgabe
2021/Nov/Tue[2] 2021-11-10 00:00:00