Time Points
Represent moments in time.
What Is a Time Point?
A std::chrono::time_point represents a specific moment measured from a clock's epoch. It pairs a clock with a duration since that epoch.
- Returned by
clock::now(). - Subtracting two of them yields a duration.
#include <iostream>
#include <chrono>
int main() {
using namespace std::chrono;
time_point<steady_clock> tp = steady_clock::now();
std::cout << "Captured a moment: " << (tp.time_since_epoch().count() != 0) << '\n';
return 0;
}time_since_epoch
Every time point can report its distance from the clock epoch with time_since_epoch(), which returns a duration.
#include <iostream>
#include <chrono>
int main() {
using namespace std::chrono;
auto tp = system_clock::now();
auto d = tp.time_since_epoch();
auto s = duration_cast<seconds>(d);
std::cout << "Positive epoch seconds: " << (s.count() > 0) << '\n';
return 0;
}