How can I get (using the std::chrono library) the difference between two points in time in milliseconds?
I could do that using this:
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::time_point<std::chrono::system_clock> foo = now + std::chrono::milliseconds(100);
std::chrono::duration<float> difference = foo - now;
const int milliseconds = difference.count() * 1000;
How can I get this time in milliseconds, so I can use the duration as a unsigned int, and not a float and then multiply by 1000?
chrono::duration_cast<chrono::milliseconds>(end_time - start_time).count()
– zoskaduration_cast<duration<float,std::milli>(difference).count()
. Usingduration_cast<milliseconds>(duration).count()
will truncate your digits sincemilliseconds
is basically aduration<long,milli>
. – Michele Piccolini