getting boost::gregorian dates from a string
Posted
by Chris H
on Stack Overflow
See other posts from Stack Overflow
or by Chris H
Published on 2010-04-11T19:35:46Z
Indexed on
2010/04/11
19:43 UTC
Read the original article
Hit count: 322
c++
|boost-date-time
I asked a related question yesterday
http://stackoverflow.com/questions/2612343/basic-boost-date-time-input-format-question
It worked great for posix_time ptime objects. I'm have trouble adapting it to get Gregorian date objects.
try {
stringstream ss;
ss << dateNode->GetText();
using boost::local_time::local_time_input_facet;
//using boost::gregorian;
ss.imbue(locale(locale::classic(),
new local_time_input_facet("%a, %d %b %Y ")));
ss.exceptions(ios::failbit);
ss>>dayTime;
} catch (...) {
cout<<"Failed to get a date..."<<endl;
//cout<<e.what()<<endl;
throw;
}
The dateNode->GetText() function returns a pointer to a string of the form
Sat, 10 Apr 2010 19:30:00
The problem is I keep getting an exception. So concretely the question is, how do I go from const char * of the given format, to a boost::gregorian::date object?
Thanks again.
© Stack Overflow or respective owner