使用boost :: date_time库格式化时间(以毫秒为单位)

Yli*_*sar 6 c++ formatting datetime boost

我有一个以毫秒为单位的持续时间,理想情况下我希望使用boost :: date_time库中的格式化功能进行格式化.但是,在创建了boost :: posix_time :: time_duration之后,我似乎找不到实际应用格式化字符串的方法.

Edd*_*onk 10

您需要首先将持续时间添加到时间对象,然后像这样输出:

boost::posix_time::time_facet* facet = new boost::posix_time::time_facet("%Y%m%d %H:%M:%S.%f");
std::stringstream date_stream;
date_stream.imbue(std::locale(date_stream.getloc(), facet));
date_stream << boost::posix_time::microsec_clock::universal_time();
Run Code Online (Sandbox Code Playgroud)

输出:

20100326 12:02:08.024820

测试升压1.41