如何将 boost::posix_time::ptime 转换为 YYMMDDHHMM?

How to convert boost::posix_time::ptime to YYMMDDHHMM?

我正在尝试将 boost::posix_time::ptime 转换为 YYMMDDHHMM 格式字符串。如何实现?

相关:How to convert a boost::ptime to string

#include <iostream>
#include <cstdlib>
#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/format.hpp>
int main()
{
    std::string submitDateString        = "20190911T235959";
    boost::posix_time::ptime submitPtime = boost::posix_time::from_iso_string( submitDateString );

     // Use a facet to display time in a custom format (only hour and minutes).
    std::stringstream sstream;
    boost::posix_time::time_facet* facet = new boost::posix_time::time_facet();
    facet->format("%y%m%d%H%M");
    sstream.imbue(std::locale(std::locale::classic(), facet));
    sstream << submitPtime;

    std::cout << "submit date:" << sstream.str( ) << std::endl;
}