title: How to parse date/time from a string in C++
body: <p>How to convert string with template <code>"%d.%m.%Y %H:%M:%S"</code> (for example, <em>28.05.2013 17:42:00</em>) to <code>boost::posix_time::ptime</code> or something similar?</p>
  
  <p>The following is my non-working code.</p>
  
  <pre><code>boost::posix_time::ptime stringToDateTime(const std::string &amp;text) {
    const std::locale fct
    (   std::locale::classic()
    ,   new boost::gregorian::date_input_facet("%d.%m.%Y %H:%M:%S")
    );
    std::istringstream is(text);
    is.imbue(fct);
    boost::posix_time::ptime date;
    is &gt;&gt; date;
    return date;
  }
  </code></pre>