我无法转换posix_time::ptime
为由time_t
or表示的时间戳posix_time::milliseconds
,或任何其他可以轻松打印的适当类型(来自 Epoch)。
我实际上只需要打印posix_time::ptime
以毫秒为单位的时间戳,所以如果有一种简单的方法可以以这种格式打印,我实际上不需要转换。
我无法转换posix_time::ptime
为由time_t
or表示的时间戳posix_time::milliseconds
,或任何其他可以轻松打印的适当类型(来自 Epoch)。
我实际上只需要打印posix_time::ptime
以毫秒为单位的时间戳,所以如果有一种简单的方法可以以这种格式打印,我实际上不需要转换。
此代码将打印自 1941-12-07T00:00:00 以来的毫秒数。显然,您可以选择适合您需要的任何时代。
void print_ptime_in_ms_from_epoch(const boost::posix_time::ptime& pt)
{
using boost::posix_time::ptime;
using namespace boost::gregorian;
std::cout << (pt-ptime(date(1941, Dec, 7))).total_milliseconds() << "\n";
}