tags:

views:

14

answers:

1

Hi,

Using the boost library how would I convert a date object:

 date d(2010,10,01); 

to a string with the format: DD-mmm-YYYY, so that variable d would become "01-Oct-2010".

Now there are number of functions for converting a date object to a string such as

 std::string to_simple_string(date d)

which returns a string in the format YYYY-mmm-DD. But I was unable to find the format I need.

Thanks!

+1  A: 

Have you read the documentation about date facet? The example appears like it should work for your scenario.

//example to customize output to be "LongWeekday LongMonthname day, year"
//                                  "%A %b %d, %Y"
date d(2005,Jun,25);
date_facet* facet(new date_facet("%A %B %d, %Y"));
std::cout.imbue(std::locale(std::cout.getloc(), facet));
std::cout << d << std::endl;
// "Saturday June 25, 2005"
Sam Miller