Epoch time to date/time format in boost c++

Viewed 3333

In Linux, i am reading epoch time from "/proc/stat" as btime and i want to convert to readable date and time format with c++ boost.

I have tried below things and date is working properly.

    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());

Here i am getting correct year and day. BUT How can i get time( HH::MM:SS) from above epoch time ? Let me give hint - i can try.

Thanks in Advance.

2 Answers
Related