C ++ - 从 ptime 计算毫秒总秒数

C++ - Calculate the millisecond from ptime in total seconds

如何计算与以下 Ptime 的毫秒差,我正在使用 boost::ptime 我正在尝试以毫秒为单位计算 time_duration 以找出差异。我得到像 999975 这样的值,但预期值为 975

ptime PreviousgpsTime = 周一 6 月 28 日 17:07:10.054 2021 ptime NextgpsTime = 6 月 28 日星期一 17:07:11.025 2021

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

如何解决这个问题并获取实际持续时间。

直播On 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 << "ms\n";
}

版画

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