In the example at http://en.cppreference.com/w/cpp/chrono the seconds value is obtained in a double
. This is the behavior I want. However, this appears to rely on the implicit assumption that the time point subtraction yields a value that represents seconds. I can not find anything that explains why a duration yields floating point seconds when no time units are actually specified. Without using auto
at all, can someone show how to explicitly obtain a time unit such as seconds in a floating point type, or point me to documentation or explanation as to why the aforementioned conversion represents seconds?
The conversion in question is essentially:
std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
std::chrono::time_point<std::chrono::system_clock> end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start; // why does this represent seconds as opposed to some other time unit?
double secondsInDouble = elapsed_seconds.count();
See the following posts for examples of the conversion.
How to get duration, as int milli's and float seconds from <chrono>?
C++ chrono - get duration as float or long long