Skip to content

Instantly share code, notes, and snippets.

@redotics
Created September 19, 2013 23:38
Show Gist options
  • Save redotics/6631387 to your computer and use it in GitHub Desktop.
Save redotics/6631387 to your computer and use it in GitHub Desktop.
Manipulate Boost posix time output # g++ boostposixtime.cpp -o boostposixtime; ./boostposixtime
// to have the cout ("equivalent" to printf)
#include <iostream>
// to have string stream
#include <sstream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
using namespace boost::posix_time;
using namespace std;
int main(int argc, char **argv) {
//time_facet *facet = new time_facet("%d-%b-%Y %H:%M:%S");
time_facet *facet1 = new time_facet("%a, %d %b %Y %H:%M:%S %Z");
time_facet *facet2 = new time_facet("%a, %d %b %Y %H:%M:%S GMT");
stringstream MyStr;
cout.imbue(locale(cout.getloc(), facet1));
MyStr.imbue(locale(cout.getloc(), facet2));
cout << second_clock::local_time() << endl;
cout << microsec_clock::universal_time() << endl;
MyStr << microsec_clock::universal_time() ;
cout << "--- Display My own string: " << MyStr.str() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment