-2
如何将字符串与模板"%d.%m.%Y %H:%M:%S"
(例如,28.05.2013 17:42:00)转换为boost::posix_time::ptime
或类似的东西?如何从C++中的字符串解析日期/时间
以下是我的非工作代码。
boost::posix_time::ptime stringToDateTime(const std::string &text) {
const std::locale fct
( std::locale::classic()
, new boost::gregorian::date_input_facet("%d.%m.%Y %H:%M:%S")
);
std::istringstream is(text);
is.imbue(fct);
boost::posix_time::ptime date;
is >> date;
return date;
}