std::chrono::year_month_weekday:: operator sys_days, std::chrono::year_month_weekday:: operator local_days
From cppreference.net
<
cpp
|
chrono
|
year month weekday
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::chrono::year_month_weekday
| Member functions | ||||
|
year_month_weekday::operator sys_days
year_month_weekday::operator local_days
|
||||
| Nonmember functions | ||||
| Helper classes | ||||
|
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
zu einem
std::chrono::time_point
, das dasselbe Datum wie dieses
year_month_weekday
repräsentiert.
1)
Wenn
year
(
)
.
ok
(
)
&&
month
(
)
.
ok
(
)
&&
weekday
(
)
.
ok
(
)
:
-
-
Wenn
index
(
)
==
0
, gibt ein
sys_dayszurück, das das Datum 7 Tage vor dem erstenweekday()des Jahres und Monats repräsentiert. -
Andernfalls gibt ein
sys_dayszurück, das das Datum ( index ( ) - 1 ) * 7 Tage nach dem ersten weekday() des Jahres und Monats repräsentiert.
-
Wenn
index
(
)
==
0
, gibt ein
Andernfalls ist der zurückgegebene Wert nicht spezifiziert.
2)
Gleich wie
(1)
, gibt jedoch
local_days
statt
sys_days
zurück. Entspricht
local_days
(
sys_days
(
*
this
)
.
time_since_epoch
(
)
)
.
Beispiel
Diesen Code ausführen
#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