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

不想你离开。 提交于 2020-01-06 12:46:15

问题


I need to format my ptime in such way Wed, 21 Jan 2004 19:51:30 GMT How to do such thing with boost? (so it would look like data format of HTTP servers Expires and Last-Modified and Date response headers )


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

See Date Time Input/Output for more information on the available format flags.



来源:https://stackoverflow.com/questions/5689421/boost-ptime-how-to-format-data-in-a-way-browsers-send-inside-headers-of-http-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!