Convert date object to string in boost
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开发者_StackOverflow社区 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!
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"
精彩评论