[date_time] local_time_facet to format strings

Hi there, I'm trying to format a time string based on a local_time_facet. For some reason it isn't working as expected. Here is the code (I basically copied from the Date Time IO Tutorial): ptime t( microsec_clock::local_time() ); std::stringstream ss; local_time_facet* output_facet = new local_time_facet(); ss.imbue( std::locale( std::locale::classic(), output_facet)); output_facet->format("%a %b %d, %H:%M %z"); ss.str(""); ss << t; std::cout << ss.str() << std::endl; The output isn't formated in the way it's specified. Cout will basically spit out the same result as to_simple_string(). 2006-Feb-03 16:38:57.046875 The expected result would something like this: Fri Feb 3, 16:38 EDT I'm using MSVC 7.1 and Boost 1.33.1. Thanks in advance, Christian

"Christian Henning"
Hi there, I'm trying to format a time string based on a local_time_facet. For some reason it isn't working as expected. Here is the code (I basically copied from the Date Time IO Tutorial):
ptime t( microsec_clock::local_time() );
std::stringstream ss;
local_time_facet* output_facet = new local_time_facet(); ss.imbue( std::locale( std::locale::classic(), output_facet));
output_facet->format("%a %b %d, %H:%M %z"); ss.str(""); ss << t; std::cout << ss.str() << std::endl;
The output isn't formated in the way it's specified. Cout will basically spit out the same result as to_simple_string().
2006-Feb-03 16:38:57.046875
That would be because you are attempting to use a local_time_facet to output a ptime. Use either a time_facet to output a ptime object, or a local_time_facet to output a local_date_time object. Bart
participants (2)
-
Bart
-
Christian Henning