我使用提升日期时间来计算特定日期的unix时间。 在大多数情况下,返回的值是正确的,但有时候计算的 秒数不正确。将ptime提升为unix时间戳转换错误
这是一个例子:
boost::posix_time::ptime t(boost::gregorian::date(1900, 1, 1));
boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
boost::posix_time::time_duration dur;
dur = t - epoch;
int tstamp = dur.total_seconds();
if (t < epoch) tstamp = -tstamp ;
期望值是-2208902400,但我得到-2085978496。 你有解决这个问题的方法吗?
不是很明显 - 在我的系统上''time_t'是64位,我得到了32位错误。实际上在代码中甚至没有提到'time_t'。这似乎是一个不足之处。 – 2012-04-26 13:37:50