Get double from boost :: chrono :: stable_clock :: now ()

How to get double value from boost :: chrono :: stable_clock :: now ()? I do not believe that there is a .count () parameter for this.

Why do I need it? I have a method that cannot parse boost return.

+4
source share
2 answers

When we put it all together, it boils down to the following:

 auto now = boost::chrono::steady_clock::now().time_since_epoch(); auto timeSinceEpoch = boost::chrono::duration_cast<boost::chrono::milliseconds>(now).count(); 

Suppose it’s not a double , but close enough: you can change the duration_cast to get any precision you need and / or split the timeSinceEpoch to your liking so that your double matches your requirements. For instance:

 // Days since epoch, with millisecond (see duration_cast above) precision double daysSinceEpoch = double(timeSinceEpoch) / (24. * 3600. * 1000.); 
+9
source

you can specify double inside duration :

 auto some_time = std::chrono::high_resolution_clock::now(); double duration = std::chrono::duration_cast<std::chrono::duration<double>>(some_time).count(); 
+8
source

Source: https://habr.com/ru/post/1482242/


All Articles