How do I convert boost::posix_time::ptime to time_t?
Since @icecrime’s method converts twice (ptime uses linear representation internally), I’ve decided to use direct computation instead. Here it is: time_t to_time_t(boost::posix_time::ptime t) { using namespace boost::posix_time; ptime epoch(boost::gregorian::date(1970,1,1)); time_duration::sec_type x = (t – epoch).total_seconds(); // … check overflow here … return time_t(x); } EDIT: Thanks @jaaw for bringing this to my attention. Since boost … Read more