【发布时间】:2016-10-06 22:23:02
【问题描述】:
我有以下代码从 posix_time 获取 UNIX 时间
boost::posix_time::ptime time1(boost::gregorian::date(9999,12,31));
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
boost::posix_time::time_duration diff = time1-epoch;
cout<<"A: "<<time1<<endl;
cout<<"B: "<<epoch<<endl;
cout<<"C: "<<diff<<endl;
unix_time = diff.total_seconds()
给我这个输出
9999-Dec-31 00:00:00
1970-Jan-01 00:00:00
-1347834:03:51.933722624
现在diff 不应该是负数。我怎样才能正确计算?有溢出吗?
【问题讨论】:
-
long long, 但diff已经是负数了 -
这可能就是你要找的:en.wikipedia.org/wiki/Year_2038_problem
-
我不使用原来的 32 位 unix 时间
-
好信息,因为它看起来确实是这样。
-
您是否将
-DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG设置为纳秒精度?我怀疑这是问题所在,我认为这会减少支持的日期范围(在 2262 年某处) - 尽管您需要详细调查代码以查看其失败的位置..
标签: c++ boost boost-date-time