Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

unsigned long long to std::chrono::time_point and back

I am very confused about something. Given:

std::time_t tt = std::time(0);
std::chrono::system_clock::time_point tp{seconds{tt} + millseconds{298}};
std::cout << tp.time_since_epoch().count();

prints something like: 16466745672980000 (for example)

How do I rehydrate that number back into a time_point object? I find myself doing kooky things (that I’d rather not show here) and I’d like to ask what the correct way to do the rehydration is.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

system_clock::time_point tp{system_clock::duration{16466745672980000}};

The units of system_clock::duration vary from platform to platform. On your platform I’m guessing it is 1/10 of a microsecond.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading