Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将时间戳(以毫秒为单位)转换为boost ptime_C++_Datetime_Boost - Fatal编程技术网

C++ 将时间戳(以毫秒为单位)转换为boost ptime

C++ 将时间戳(以毫秒为单位)转换为boost ptime,c++,datetime,boost,C++,Datetime,Boost,我需要将从历元开始以毫秒为单位测量的时间转换为aboost::posix_time::ptime。我看到的唯一功能是从_time _t转换为,但这仅以秒为单位,并且会损失毫秒 如何将自历元起的毫秒数转换为ptime类型?其中ms是自历元起的毫秒数: from_time_t(millis / 1000) + millisec(millis % 1000) ptime epoch_milliseconds_to_ptime(unsigned long int ms) { static cons

我需要将从历元开始以毫秒为单位测量的时间转换为a
boost::posix_time::ptime
。我看到的唯一功能是从_time _t转换为,但这仅以秒为单位,并且会损失毫秒


如何将自历元起的毫秒数转换为ptime类型?

其中
ms
是自历元起的毫秒数:

from_time_t(millis / 1000) + millisec(millis % 1000)
ptime epoch_milliseconds_to_ptime(unsigned long int ms)
{
  static const ptime epoch(date(1970, 1, 1));

  return epoch + milliseconds(ms);
}
是的,这应该行得通(有时简单的答案可能很难找到;)