开发者

Local time with milliseconds

开发者 https://www.devze.com 2023-01-04 20:19 出处:网络
how can I get current time with library boost. 开发者_如何学编程I can do this: ptime now = boost::posix_timesecond_clock::local_time();

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?


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;
}


I think the code should be:

 ptime now = boost::posix_time::second_clock::local_time();

I think you forget the "::" in the codes. ^_^

0

精彩评论

暂无评论...
验证码 换一张
取 消