本地时间,以毫秒为单位

Max*_*rai 14 c++ time boost

如何通过库增强获得当前时间.我可以做这个:

ptime now = boost::posix_timesecond_clock::local_time();
tm d_tm = to_tm(now);
Run Code Online (Sandbox Code Playgroud)

但最后一次tm结构的单位是秒,我需要毫秒.我可以用毫秒获得当前时间吗?

Sam*_*ler 18

看看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;
}
Run Code Online (Sandbox Code Playgroud)