C++ - Convert AM/PM time string to posix time ptime
<p>I'm trying to convert a time string to <code>boost::posix_time::ptime</code> object, but the conversion is not working.This is the function thats being used. </p>

<pre><code>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 &lt;&lt; datetime;
  date_strm &gt;&gt; pt;

  date_res &lt;&lt; pt.date().year() &lt;&lt; "-" &lt;&lt; std::setw(2) &lt;&lt; std::setfill('0') &lt;&lt; pt.date().month().as_number()
           &lt;&lt; "-" &lt;&lt; std::setw(2) &lt;&lt; std::setfill('0') &lt;&lt; pt.date().day() &lt;&lt; " "
           &lt;&lt; pt.time_of_day().hours() &lt;&lt; ":" &lt;&lt; pt.time_of_day().minutes() &lt;&lt; ":" &lt;&lt; pt.time_of_day().seconds();

  return date_res.str();
}
</code></pre>

<p>With a input time string of <code>2016-Feb-29 2:00:00 AM</code>, this function is returning <code>Thu Dec 3 04:00:54 287564</code> 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 <code>2016-02-29 02:00:00</code></p>

<p>The <code>time_input_facet</code> thats being used in this function for the required conversion is <code>"%Y-%b-%d %H:%M:%S %p"</code></p>