【发布时间】:2016-02-20 12:19:44
【问题描述】:
我有一个来自我正在使用的库的函数,它需要一个双精度作为参数。它需要传递一个纳秒类型的偏移量加上 sytem_clock::now()。到目前为止我有这个代码:
system_clock::time_point now = std::chrono::system_clock::now();
auto timepointoffset = (now + desiredOffset);
我怎样才能使它成为双倍?
编辑:所以我需要补充一点,问题是我需要这样做而不会有丢失数据的风险。我有这个代码:
system_clock::time_point now = std::chrono::system_clock::now();
auto timepointoffset = std::chrono::time_point_cast<std::chrono::nanoseconds>(now + desiredOffset);
double value = timepointoffset.time_since_epoch().count();
问题是编译器说可能会丢失数据。
【问题讨论】:
-
您在问题中没有提到 ntp。它是如何成为相关标签的?
-
你试过
double newTime = static_cast<double>(timepointoffset);或类似的东西吗? -
马特,我试过了,但它不起作用。