Boost ptime:如何以浏览器在http请求的header内发送的方式格式化数据

Boost ptime: how to format data in a way browsers send inside headers of http requests?

本文关键字:header 格式化数据 方式 请求 http ptime 浏览器 Boost      更新时间:2023-10-16

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

#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();
}

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