【发布时间】:2018-02-28 02:01:40
【问题描述】:
在 Linux 中,我从“/proc/stat”读取纪元时间作为 btime,我想使用 c++ boost 转换为可读的日期和时间格式。
我已经尝试了以下事情并且日期工作正常。
time_t btime_ = 1505790902; //This is epoch time read from "/proc/stat" file.
std::wstring currentDate_ = L"";
boost::gregorian::date current_date_ =
boost::posix_time::from_time_t(btime_).date();
std::wstring year_ = boost::lexical_cast<std::wstring>
(current_date_.year());
std::wstring day_ = boost::lexical_cast<std::wstring>
(current_date_.day());
在这里,我得到了正确的年份和日期。但是我怎样才能从上面的纪元时间获得时间(HH::MM:SS)?让我提示一下 - 我可以试试。
提前致谢。
【问题讨论】:
标签: c++ boost boost-date-time