1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// duration_cast
#include <iostream>
#include <ratio>
#include <chrono>
int main ()
{
typedef std::chrono::duration<int> seconds_type;
typedef std::chrono::duration<int,std::milli> milliseconds_type;
seconds_type s (1); // 1 second
milliseconds_type ms = std::chrono::duration_cast<milliseconds_type> (s);
ms += milliseconds_type(2500); // 3500 millisecond
s = std::chrono::duration_cast<seconds_type> (ms); // truncated
std::cout << "ms: " << ms.count() << std::endl;
std::cout << "s: " << s.count() << std::endl;
return 0;
}
|