我试图通过使用预定义的格式简单地将boost C ++中的ptime对象转换为字符串。
遵循这种逻辑的东西。
#include "boost/date_time/posix_time/posix_time.hpp"
ptime timeObj = time_from_string("2002-01-20 23:59:59");
timeObj.format("%m %d");
string result = timeObj.toString();
然而,我能找到的最接近的是使用date_facet / time_facet格式化时间,然后将其输出到流,如本示例中的boost: http://www.boost.org/doc/libs/1_49_0/doc/html/date_time/date_time_io.html#date_time.date_facet
//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"
我很想知道是否有更简单的方法来做到这一点。 在此先感谢:)