Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using time facets on universal_time

on boost, to create a time facet to format an specified time we use the folowing:

boost::local_time::local_time_facet* facet = new boost::local_time::local_time_facet("%Y%m%d %H:%M:%S.%f");
std::stringstream date_stream;
date_stream.imbue(std::locale(date_stream.getloc(), facet));
date_stream << boost::local_time::local_microsec_clock::local_time(boost::local_time::time_zone_ptr());

How do I do the same thing, but using an universal clock:

boost::posix_time::microsec_clock::universal_time()

Thanks

like image 783
scooterman Avatar asked Mar 25 '10 14:03

scooterman


1 Answers

I know that by now scooterman has either found the answer or doesn't care anymore (:D), but in the case that someone found this question while searching (like i did), here's the answer:

boost::posix_time::ptime time(microsec_clock::universal_time());
std::stringstream ss;
boost::date_time::time_facet *facetPtr 
              = new boost::date_time::time_facet("%a, %d %b %Y %H:%M:%S.%f GMT");
ss.imbue(std::locale(ss.getloc(), facetPtr));
ss << time;
//ss.str() contains the formatted time string
like image 169
p00ya00 Avatar answered Oct 23 '22 10:10

p00ya00