I need to convert std::chrono::time_point
to and from a long
type (integer 64 bits). I´m starting working with std::chrono
...
Here is my code:
int main ()
{
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
auto epoch = now.time_since_epoch();
auto value = std::chrono::duration_cast<std::chrono::milliseconds>(epoch);
long duration = value.count();
std::chrono::duration<long> dur(duration);
std::chrono::time_point<std::chrono::system_clock> dt(dur);
if (dt != now)
std::cout << "Failure." << std::endl;
else
std::cout << "Success." << std::endl;
}
This code compiles, but does not show success.
Why is dt
different than now
at the end?
What is missing on that code?