在universal_time上使用时间面

sco*_*man 5 c++ datetime boost

在boost,创建时间方面格式化指定时间我们使用下面的内容:

boost::local_time::local_time_facet* facet = new boost::local_time::local_time_facet("%Y%m%d %H:%M:%S.%f");
std::stringstream date_stream;
date_stream.imbue(std::locale(date_stream.getloc(), facet));
date_stream << boost::local_time::local_microsec_clock::local_time(boost::local_time::time_zone_ptr());
Run Code Online (Sandbox Code Playgroud)

我如何做同样的事情,但使用通用时钟:

boost::posix_time::microsec_clock::universal_time()
Run Code Online (Sandbox Code Playgroud)

谢谢

p00*_*a00 5

我知道现在scooterman已经找到答案或者不再关心(:D),但是如果有人在搜索时发现了这个问题(就像我一样),这就是答案:

boost::posix_time::ptime time(microsec_clock::universal_time());
std::stringstream ss;
boost::date_time::time_facet *facetPtr 
              = new boost::date_time::time_facet("%a, %d %b %Y %H:%M:%S.%f GMT");
ss.imbue(std::locale(ss.getloc(), facetPtr));
ss << time;
//ss.str() contains the formatted time string
Run Code Online (Sandbox Code Playgroud)