0

我需要以这种方式格式化我的 ptimeWed, 21 Jan 2004 19:51:30 GMT如何用 boost 做这样的事情?(所以它看起来像 HTTP 服务器和响应头的Expires数据格式Last-ModifiedDate

4

1 回答 1

2
#include <locale>
#include <string>
#include <iostream>
#include <sstream>
#include <boost/date_time/posix_time/posix_time.hpp>

std::string current_time_formatted()
{
    namespace bpt = boost::posix_time;

    static char const* const fmt = "%a, %d %b %Y %H:%M:%S GMT";
    std::ostringstream ss;
    // assumes std::cout's locale has been set appropriately for the entire app
    ss.imbue(std::locale(std::cout.getloc(), new bpt::time_facet(fmt)));
    ss << bpt::second_clock::universal_time();
    return ss.str();
}

有关可用格式标志的更多信息,请参阅日期时间输入/输出

于 2011-04-18T01:00:42.867 回答