You can use boost::posix_time::time_duration to get the time range. For example, for example,
boost::posix_time::time_duration diff = tick - now; diff.total_milliseconds();
And to get a higher resolution, you can change the clock you are using. For example, for boost::posix_time::microsec_clock , although this is OS dependent. On Windows, for example, boost::posix_time::microsecond_clock has a milisecond resolution, not a microsecond.
An example that is slightly dependent on hardware.
int main(int argc, char* argv[]) { boost::posix_time::ptime t1 = boost::posix_time::second_clock::local_time(); boost::this_thread::sleep(boost::posix_time::millisec(500)); boost::posix_time::ptime t2 = boost::posix_time::second_clock::local_time(); boost::posix_time::time_duration diff = t2 - t1; std::cout << diff.total_milliseconds() << std::endl; boost::posix_time::ptime mst1 = boost::posix_time::microsec_clock::local_time(); boost::this_thread::sleep(boost::posix_time::millisec(500)); boost::posix_time::ptime mst2 = boost::posix_time::microsec_clock::local_time(); boost::posix_time::time_duration msdiff = mst2 - mst1; std::cout << msdiff.total_milliseconds() << std::endl; return 0; }
On my win7 machine. The first output is 0 or 1000. The second resolution. The second one is almost always 500, due to the higher resolution of the watch. I hope I help a little.
mkaes Jul 18 2018-11-18T00: 00Z
source share