views:

167

answers:

1

Hello, 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?

+2  A: 

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;
}
Sam Miller
Hm, okay. And what's right form for accessing data?
Ockonal
@Ockonal I've updated my example to show how to extract the milliseconds.
Sam Miller
Great, thank you.
Ockonal