In my thread (using boost::thread) I need to retrieve the current time in ms or less and to convert into ms:
Actually, reading here I’ve found this:
tick = boost::posix_time::second_clock::local_time();
now = boost::posix_time::second_clock::local_time();
And seems to work, but after I need to have a long value of the milliseconds of the now…
How can I do it?
You can use
boost::posix_time::time_durationto get the time range. E.g like thisAnd to get a higher resolution you can change the clock you are using. For example to the
boost::posix_time::microsec_clock, though this can be OS dependent. On Windows, for example,boost::posix_time::microsecond_clockhas milisecond resolution, not microsecond.An example which is a little dependent on the hardware.
On my win7 machine. The first out is either 0 or 1000. Second resolution.
The second one is nearly always 500, because of the higher resolution of the clock. I hope that help a little.