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

How to parse date/time from string?

Although I don’t know how to format a single-digit month input in boost, I can do it after the two-digit edit: #include <iostream> #include <boost/date_time.hpp> namespace bt = boost::posix_time; const std::locale formats[] = { std::locale(std::locale::classic(),new bt::time_input_facet(“%Y-%m-%d %H:%M:%S”)), std::locale(std::locale::classic(),new bt::time_input_facet(“%Y/%m/%d %H:%M:%S”)), std::locale(std::locale::classic(),new bt::time_input_facet(“%d.%m.%Y %H:%M:%S”)), std::locale(std::locale::classic(),new bt::time_input_facet(“%Y-%m-%d”))}; const size_t formats_n = sizeof(formats)/sizeof(formats[0]); std::time_t pt_to_time_t(const bt::ptime& pt) { … Read more

deneme bonusudeneme bonusu veren sitelerOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino