how can I get current time with library boost. I can do this:
ptime now = boost::posix_timesecond_clock::local_time();
tm d_tm = to_tm(now);
But the last time unit of tm structure is second and I need in millisecond. Can I get current time with milliseconds?
The getUTCMilliseconds() method is used to get the milliseconds from a given date according to universal time (UTC). The value return by getUTCMilliseconds() method is a number between 0 and 999.
Convert from human-readable date to epoch long epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000; Timestamp in seconds, remove '/1000' for milliseconds.
currentTimeMillis() method returns the current time in milliseconds. The unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
look at boost::posix_time::microsec_clock::local_time()
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <iostream>
int
main()
{
boost::posix_time::ptime time = boost::posix_time::microsec_clock::local_time();
boost::posix_time::time_duration duration( time.time_of_day() );
std::cout << duration.total_milliseconds() << std::endl;
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With