C++ 将时间戳(以毫秒为单位)转换为boost ptime
我需要将从历元开始以毫秒为单位测量的时间转换为aC++ 将时间戳(以毫秒为单位)转换为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
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);
}
是的,这应该行得通(有时简单的答案可能很难找到;)