std::chrono::time_point::time_since_epoch
Aus cppreference.com
< cpp | chrono | time point
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
std::chrono::duration time_since_epoch() const; |
||
Gibt eine std::chrono::duration, die die Zeitspanne zwischen *this und der
clock
der Epoche .Original:
Returns a std::chrono::duration representing the amount of time between *this and the
clock
's epoch.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Parameter
(None)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Rückgabewert
die Zeitspanne zwischen dieser und der
time_point
clock
EpocheOriginal:
the amount of time between this
time_point
and the clock
's epochThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[Bearbeiten] Beispiel
#include <iostream> #include <chrono> #include <ctime> int main() { std::chrono::time_point<std::chrono::system_clock> p1, p2, p3; p2 = std::chrono::system_clock::now(); p3 = p2 - std::chrono::hours(24); std::time_t epoch_time = std::chrono::system_clock::to_time_t(p1); std::cout << "epoch: " << std::ctime(&epoch_time); std::time_t today_time = std::chrono::system_clock::to_time_t(p2); std::cout << "today: " << std::ctime(&today_time); std::cout << "hours since epoch: " << std::chrono::duration_cast<std::chrono::hours>( p2.time_since_epoch()).count() << '\n'; std::cout << "yesterday, hours since epoch: " << std::chrono::duration_cast<std::chrono::hours>( p3.time_since_epoch()).count() << '\n'; }
Possible output:
epoch: Wed Dec 31 19:00:00 1969 today: Tue Jun 19 12:05:37 2012 hours since epoch: 372256 yesterday, hours since epoch: 372232