0

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 )

rcollyer
  • 10,475
  • 4
  • 48
  • 75
Rella
  • 65,003
  • 109
  • 363
  • 636
  • 2
    http://stackoverflow.com/questions/1904317/c-boost-date-with-format-dd-mm-yyyy
    http://stackoverflow.com/questions/3786201/parsing-of-date-time-from-string-boost
    –  Apr 16 '11 at 20:53

1 Answers1

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

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

ildjarn
  • 62,044
  • 9
  • 127
  • 211