Boost logo

Boost Users :

Subject: [Boost-users] How to use %e for the format of time_input_facet?
From: xiada74_at_[hidden]
Date: 2010-09-05 09:10:16


I tried the below code:
 
#include <boost/date_time.hpp>
#include <boost/date_time/posix_time/ptime.hpp>

#include <iostream>
using namespace boost::posix_time;

int main()
{
&nbsp;&nbsp;&nbsp; std::string _format1 = "%Y-%m-%d %H:%M:%S";
&nbsp;&nbsp;&nbsp; std::string _format2 = "%Y-%m-%e %H:%M:%S";

&nbsp;&nbsp;&nbsp; std::string teststring = "2010-09-10 10:01:01";
&nbsp;&nbsp;&nbsp; ptime time1, time2;

&nbsp;&nbsp;&nbsp; time_input_facet facet1(_format1, 1);
&nbsp;&nbsp;&nbsp; time_input_facet facet2(_format2, 1);

&nbsp;&nbsp;&nbsp; std::stringstream ss1(teststring);
&nbsp;&nbsp;&nbsp; std::stringstream ss2(teststring);

&nbsp;&nbsp;&nbsp; ss1.imbue(std::locale(ss1.getloc(), &facet1));
&nbsp;&nbsp;&nbsp; ss1 >> time1;

&nbsp;&nbsp;&nbsp; ss2.imbue(std::locale(ss2.getloc(), &facet2));
&nbsp;&nbsp;&nbsp; ss2 >> time2;

&nbsp;&nbsp;&nbsp; std::cout << "Time1: " << time1 << std::endl;
&nbsp;&nbsp;&nbsp; std::cout << "Time2: " << time2 << std::endl;
&nbsp;&nbsp;&nbsp; return 0;
}

The output is:
&nbsp;
Time1: 2010-Sep-10 10:01:01
Time2: not-a-date-time

Who can help to fix the issue for the format using "%e"?
&nbsp;
Thanks in advance!



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net