std::chrono::time_point<Clock,Duration>:: time_point
From cppreference.net
<
cpp
|
chrono
|
time point
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::chrono::time_point
| Member functions | ||||
|
time_point::time_point
|
||||
|
(C++20)
(C++20)
|
||||
| Non-member functions | ||||
|
(until C++20)
(C++20)
|
||||
|
(C++17)
|
||||
|
(C++17)
|
||||
|
(C++17)
|
||||
| Helper classes | ||||
|
(C++26)
|
| (1) | ||
|
time_point
(
)
;
|
(seit C++11)
(constexpr seit C++14) |
|
| (2) | ||
|
explicit
time_point
(
const
duration
&
d
)
;
|
(seit C++11)
(constexpr seit C++14) |
|
| (3) | ||
|
template
<
class
Duration2
>
time_point ( const time_point < Clock, Duration2 > & t ) ; |
(seit C++11)
(constexpr seit C++14) |
|
Konstruiert einen neuen
time_point
aus einer von mehreren optionalen Datenquellen.
1)
Standardkonstruktor, erstellt einen
time_point
, der die Epoche des
Clock
repräsentiert (d.h.
time_since_epoch()
ist null).
2)
Konstruiert einen
time_point
zur Epoche von
Clock
plus
d
.
3)
Konstruiert einen
time_point
durch Konvertierung von
t
zu
duration
. Dieser Konstruktor nimmt nur an der Überladungsauflösung teil, wenn
Duration2
implizit in
duration
konvertierbar ist.
Parameter
| d | - |
eine
duration
zum Kopieren
|
| t | - |
einen
time_point
zur Konvertierung
|
Beispiel
Diesen Code ausführen
#include <chrono> #include <iostream> using Clock = std::chrono::steady_clock; using TimePoint = std::chrono::time_point<Clock>; void print_ms(const TimePoint& point) { using Ms = std::chrono::milliseconds; const Clock::duration since_epoch = point.time_since_epoch(); std::cout << std::chrono::duration_cast<Ms>(since_epoch) << '\n'; } int main() { const TimePoint default_value = TimePoint(); // (1) print_ms(default_value); // 0ms const Clock::duration duration_4_seconds = std::chrono::seconds(4); const TimePoint time_point_4_seconds(duration_4_seconds); // (2) // 4 Sekunden ab Beginn der Epoche print_ms(time_point_4_seconds); // 4000ms const TimePoint time_point_now = Clock::now(); // (3) print_ms(time_point_now); // 212178842ms }
Mögliche Ausgabe:
0ms 4000ms 212178842ms
Siehe auch
|
Konstruiert eine neue Duration
(öffentliche Elementfunktion von
std::chrono::duration<Rep,Period>
)
|
|
|
(C++11)
|
Konvertiert eine Duration in eine andere mit einem anderen Taktintervall
(Funktionstemplate) |