Hello
I have to output current date/time on my computer including timezone in this format:
Date: Tue, 15 May 2007 09:21:48 -0400
-0400 is a timezone
Im not really familiar with timezones and I could not understand the documentation how to get local timezone on my computer..
If i'm in gmt + 1, my program should know this and output 0100
Anyone has an idea how to do this?
The code I have so far:
Code:
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/local_time/local_time.hpp>
#include <boost/date_time/local_time/posix_time_zone.hpp>
#include <boost/date_time/date_facet.hpp>
#include <ctime>
#include <locale>
#include <memory>
#include <sstream>
#include <boost/shared_ptr.hpp>
std::string mystrftime(const std::string format, time_t time,
const std::locale& locale = std::locale::classic()) {
boost::shared_ptr<boost::local_time::time_zone> tz(new boost::local_time::posix_time_zone("M1.0.0"));
boost::local_time::local_date_time dt(boost::posix_time::from_time_t(time), tz);
boost::local_time::local_time_facet *ff = new boost::local_time::local_time_facet();
ff->format(format.c_str());
std::stringstream s;
s.imbue(std::locale(std::locale::classic(), ff));
s << dt;
return s.str();
}
int main () {
std::cout << mystrftime("%A, %B %d, %Y %q", std::time(0)) << '\n';
}