views:

1356

answers:

1

I want to use the date_time library in boost to represent time in my application. This application will generate Atom feeds, which in turn mandates time-stamps in the format specified in RFC 3339, for example "1990-12-31T23:59:60Z" or "1990-12-31T15:59:60-08:00".

So, how do I format time according to this RFC?

I have been reading the Date Time Input/Output documentation all day, and I can't seem to find out how to put the Z at the end when I need it. Also, the RFC supports an optional fractional second, but only one digit of it (eg. "1990-12-31T23:59:60.5Z") (*). I can't seem to find out how to do this either.

I could always write my own formatting routine that reads out the different needed fields, but that seems to me to be working against the grain of the date_time library.

Any experience with writing formatters for this library? Or am I doing the wrong thing?

(*): It seems to me that the ABNF given in the RFC only allows one-digit fractional seconds, but the examples in the same RFC have two-digit fractional seconds. What is that supposed to mean?

+4  A: 
Slimak
Ah. Thanks. Nice. I never got the time zone stuff completely right. Maybe I should try to learn the library *first*? :)
Magnus Hoff
BTW, you might want to use the `time_zone_ptr`-typedef rather than `boost::shared_ptr<posix_time_zone>`.
Magnus Hoff
Ptr corrected. BTW I do not use this library currently --- I was considering switch to it from wxWidgets date and time used in one project some time ago, and learned it a bit by the way. And refreshing memory was a nice break during some test plan preparation :).
Slimak