开发者

Formatting time in milliseconds using boost::date_time library

I have a time duration in milliseconds which I ideally would like to format using the formatting functionality present in the boost::date_time library. However, after creating a boost::posix_time::time_duration I can't seem开发者_运维知识库 to find a way to actually apply the formatting string to it.


You need to add the duration to a time object first, and then output it like this:

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();

output:

20100326 12:02:08.024820

Tested with boost 1.41

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜