我使用boost::posix_time::ptime
来衡量我的模拟运行时间和其他东西。获得提升:: posix_time :: time_duration在几秒钟内
assuimg
boost::posix_time::ptime start, stop;
boost::posix_time::time_duration diff;
start = boost::posix_time::microsec_clock::local_time();
sleep(5);
stop = boost::posix_time::microsec_clock::local_time();
diff = stop - stop;
现在
std::cout << to_simple_string(diff) << std::endl;
回报在hh:mm:ss.ssssss
格式的时间,我想有时间,以及在ss.sssssss
。
这样做,我想
boost::posix_time::time_duration::sec_type x = diff.total_seconds();
但给我的答案SS的格式和seconds()
回报返回秒标准化数(0..60)。
我的问题我怎样才能得到我的模拟时间在ss.ssssss格式的秒钟?
编辑
我是能够做到:
std::cout << diff.total_seconds() << "." << diff.fractional_seconds() << std::endl;
是有什么高雅,可以绘制ss.sssssss?
感谢您的重播。根据你的例子,我想要以下输出:62.0000(ss.ssssss)。可能吗? – Eagle 2012-02-08 14:56:09
@Eagle:我用'boost :: format'添加了一个你想要的输出的例子。希望能帮助到你。 – nabulke 2012-02-08 18:41:54