C++-从ptime开始计算毫秒(以秒为单位)



如何计算与以下Ptime的毫秒差,我正在使用boost::Ptime我正试图计算以毫秒为单位的持续时间来找出差异。我得到的值是999975,但预期值是975

ptime Previousgsps时间=2021年6月28日星期一17:07:10.054ptime NextgpsTime=2021年6月28日星期一17:07:11.025

double totalDiff = (NextgpsTime-PreviousgpsTime).total_milliseconds();

如何修复此问题并获得实际持续时间。

在Coliru上直播:

#include <boost/date_time/posix_time/posix_time.hpp>
int main()
{
using namespace boost::posix_time;
ptime PreviousgpsTime = time_from_string("2021-Jun-28 17:07:10.054");
ptime NextgpsTime     = time_from_string("2021-Jun-28 17:07:11.025");
long totalDiff = (NextgpsTime - PreviousgpsTime).total_milliseconds();
std::cout << "From " << PreviousgpsTime << " to " << NextgpsTime << " is " << totalDiff << "msn";
}

打印

From 2021-Jun-28 17:07:10.054000 to 2021-Jun-28 17:07:11.025000 is 971ms

相关内容

  • 没有找到相关文章

最新更新