Reputation: 1359
I am trying to read/write dates in this format: yyyy-mm-ddThh:mm:ssZ
I'm doing this :
boost::posix_time::ptime t = boost::posix_time::time_from_string( "2012-02-20T00:26:39Z" );
std::cout << boost::posix_time::to_iso_extended_string( t ) << std::endl;
it works if I remove the final Z, but if I keep it an exception is thrown (bad lexical cast: source type value could not be interpreted as target).
Is there a better way to handle those dates, without manually removing/adding the Z? From what I read here and there, I understand the Z means GMT and if it's not present it means the time is in the local time zone. I'd like some generic and bugfree version to read it.
Upvotes: 1
Views: 2544
Reputation: 5480
Check out the section on formatting strings in the Boost.DateTime IO Tutorial.
http://www.boost.org/doc/libs/1_48_0/doc/html/date_time/date_time_io.html#format_strings
I thin you'll find your answers there.
Upvotes: 1