I'm having trouble in formatting the local time in W3C format. The format is described at http://www.w3.org/TR/NOTE-datetime as follows:
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
My first attempt was to use a ptime as follows:
boost::posix_time::ptime t(boost::posix_time::microsec_clock::local_time());
boost::posix_time::time_facet* output_facet = new boost::posix_time::time_facet();
ss.imbue(std::locale(std::locale::classic(), output_facet));
output_facet->format("%Y-%m-%dT%H:%M:%S%f%Q");
ss << t;
But when using a ptime in combination with a time_facet, the time zone (%Q) is ignored (also mentioned in the documentation http://www.boost.org/doc/libs/1_34_1/doc/html/date_time/date_time_io.html)
So i thought to switch to the local time library which gives me the following code:
typedef boost::date_time::time_facet<boost::local_time::local_date_time, char> ldt_facet;
ldt_facet* output_facet = new ldt_facet("%Y-%m-%dT%H:%M:%S%f%Q");
ss.imbue(std::locale(std::locale::classic(), output_facet));
boost::local_time::time_zone_ptr zone; <===========
boost::local_time::local_date_time ldt1(boost::posix_time::microsec_clock::local_time(), zone);
ss << ldt1;
Problem here is that i have to provide the timezone where the software is running, which (offcourse) i do not know and actually would like the boost library to do this for me ;)
After searching the web and reading the unittests i have found some clue's how i could make it work by first getting the difference between localtime and universial time and then format the timezone part myself. This will be much trouble for something that (i believe) should be in the library already.
So my question is:
How can i format the local time in W3C format (without providing the time zone myself)?
Environment info:
- Windows XP
- VC2005
- Boost 1_34_1
Thanks for any hints & tips,
Paul
Express yourself instantly with MSN Messenger! MSN Messenger