【发布时间】:2013-02-07 11:11:01
【问题描述】:
我正在尝试编写一个简单的时间戳系统,它提供从当前时间开始的纪元秒和小数秒。我正在使用 boost 库并且有这样的东西:
const boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
boost::posix_time::ptime time() {
boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
return now;
}
boost::posix_time::time_duration dur = (time() - epoch);
然后使用以下元素提取纪元值:
dur.total_seconds();
dur.fractional_seconds();
具体来说,这会返回正确的 unix 时间吗?如果没有,关于如何纠正它的任何建议?谢谢。
【问题讨论】:
标签: c++ date boost timestamp unix-timestamp