1

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.

foke
  • 1,339
  • 2
  • 12
  • 20
  • Can you add a reference about the `Z`? Because I cannot find it anywhere, related to boost:posix_time and parsing from string. – Irfy Feb 20 '12 at 00:45
  • there is no mention of Z in the boost docs, I just happen to get that kind of dates. I found the signification of Z here: http://www.cl.cam.ac.uk/~mgk25/iso-time.html – foke Feb 20 '12 at 00:51
  • "Z" comes from the ISO 8601 standard and it means UTC (universal time) and is equivalent to +00:00. http://en.wikipedia.org/wiki/ISO_8601 – Mischa Arefiev Feb 19 '14 at 12:47

1 Answers1

1

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.

Sean
  • 5,290
  • 2
  • 24
  • 21