Yes, but you just use the standard c library mechanisms.
set the desired time zone in the environment by creating a line:
std::string tz = "TZ=Australia/Sydney";
putenv(const_cast<char *>(tz.c_str()));
tzset();
time_t aTime = time(NULL);
struct tm retTime;
localtime_r(aTime, &retTime);
char destString[1024];
strftime(destString, 1023, "%Y%m%d %Z", &retTime);
std::cout << destString << std::endl;
The problem is that this code is not thread safe - multiple threads that change time zone information do not end well.
This answer gives you the opportunity to do this with boost, which is certainly much simpler.
source
share