I'm trying to convert a time string to boost::posix_time::ptime object, but the conversion is not working.This is the function thats being used.
std::string Parser::getFormattedDate(std::string datetime)
{
std::stringstream date_strm, date_res;
boost::posix_time::ptime pt;
boost::posix_time::time_input_facet *facet = new boost::posix_time::time_input_facet( "%Y-%b-%d %H:%M:%S %p" );
date_strm.imbue( std::locale( std::locale(), facet ));
date_strm << datetime;
date_strm >> pt;
date_res << pt.date().year() << "-" << std::setw(2) << std::setfill('0') << pt.date().month().as_number()
<< "-" << std::setw(2) << std::setfill('0') << pt.date().day() << " "
<< pt.time_of_day().hours() << ":" << pt.time_of_day().minutes() << ":" << pt.time_of_day().seconds();
return date_res.str();
}
With a input time string of 2016-Feb-29 2:00:00 AM, this function is returning Thu Dec 3 04:00:54 287564 which is obviously not correct. How can i get the correct date time from that input ? In this case the correct date time should be 2016-02-29 02:00:00
The time_input_facet thats being used in this function for the required conversion is "%Y-%b-%d %H:%M:%S %p"