【发布时间】:2012-02-08 13:27:57
【问题描述】:
我正在使用 boost::posix_time::ptime 来测量我的模拟运行时间以及其他用途。
假设
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 吗?
【问题讨论】: