Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ time_t to std::string for a specific time zone

Tags:

c++

posix

time

In a Linux environment working in C++, I need to convert a time_t value into an English string representation for various time zones. e.g. 1305750080 -> "2011-05-18 13:21:20 PST". I am able to use gmtime() or localtime() combined with strftime() to generate strings for GMT and my local timezone. How would I select an alternative time zone?

like image 295
Amish Programmer Avatar asked Dec 11 '25 18:12

Amish Programmer


1 Answers

gmtime() reference link here has an example showing a very simple way of applying time zone offsets. Naturally you could create a class with an enum or something and come up with something a little nicer.

Alternately boost::date_time has a pretty extensive implementation that works on linux and windows.

like image 151
AJG85 Avatar answered Dec 14 '25 08:12

AJG85