在 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());
我如何做同样的事情,但使用通用时钟:
boost::posix_time::microsec_clock::universal_time()
谢谢
最佳答案
我知道现在 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
关于c++ - 在 universal_time 上使用时间方面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2516165/