如何将boost::posix_time::ptime转换为YYMMDDHHMM?
我正在尝试将boost::posix_time::ptime转换为YYMMDDHHMM格式的字符串。如何做到这一点 相关:如何将boost::posix_time::ptime转换为YYMMDDHHMM?,boost,date-formatting,Boost,Date Formatting,我正在尝试将boost::posix_time::ptime转换为YYMMDDHHMM格式的字符串。如何做到这一点 相关:#包括 #包括 #包括 #包括 #包括 int main() { std::string submitDateString=“20190911T23559”; boost::posix_time::ptime submitpttime=boost::posix_time::from_iso_字符串(submitDateString); //使用方面以自定义格式显示时间(仅小时
#包括
#包括
#包括
#包括
#包括
int main()
{
std::string submitDateString=“20190911T23559”;
boost::posix_time::ptime submitpttime=boost::posix_time::from_iso_字符串(submitDateString);
//使用方面以自定义格式显示时间(仅小时和分钟)。
std::stringstream和ssstream;
boost::posix_time::time_facet*facet=新的boost::posix_time::time_facet();
刻面->格式(“%y%m%d%H%m”);
imbue(std::locale(std::locale::classic(),facet));
溪流
#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;
}