I'm converting a std::chrono::time_point<std::chrono::high_resolution_clock>
timestamp using
std::chrono::duration_cast<std::chrono::milliseconds>(
getTimestamp().time_since_epoch()
).count()
to a 64 bit timestamp with millisecond precision. This is needed for some serialization in between of data. Later on I need to convert those timestamps back to a std::chrono::time_point<std::chrono::high_resolution_clock>
for further processing. What is the proper way to do this in C++11?
> class time_point; (since C++11) Class template std::chrono::time_point represents a point in time. It is implemented as if it stores a value of type Duration indicating the time interval from the start of the Clock 's epoch. Clock must meet the requirements for Clock or be std::chrono::local_t (since C++20).
constexpr duration time_since_epoch() const; (since C++14) Returns a duration representing the amount of time between *this and the clock 's epoch.
The Chronos Numbers are like a clock because Chronos means time so it will be time numbers and since there are twelve members (Number 13 is a special agent so wouldn't count with the rest of the numbers) like the face of a clock.
Chrono in C++ The unique thing about chrono is that it provides a precision-neutral concept by separating duration and point of time (“timepoint”) from specific clocks.
Convert the number of milliseconds to a duration and add it to an epoch time_point
:
auto epoch = std::chrono::time_point<std::chrono::high_resolution_clock>();
auto since_epoch = std::chrono::milliseconds(deserialised);
auto timestamp = epoch + since_epoch;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With