Boost logo

Boost Users :

From: Paul Bormans (pbor1234_at_[hidden])
Date: 2008-08-26 02:30:18


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! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net