【问题标题】:Boost ptime: how to format data in a way browsers send inside headers of http requests?Boost ptime:如何以浏览器在 http 请求的标头内发送的方式格式化数据?
【发布时间】:2011-08-07 01:27:35
【问题描述】:

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

【问题讨论】:

标签: c++ boost boost-date-time


【解决方案1】:
#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();
}

有关可用格式标志的更多信息,请参阅Date Time Input/Output

【讨论】:

    猜你喜欢
    • 2010-09-28
    • 2021-09-20
    • 1970-01-01
    • 2014-09-28
    • 2016-01-16
    • 1970-01-01
    • 2018-04-07
    • 2013-12-18
    相关资源
    最近更新 更多