C++ – std::mktime and timezone info


I'm trying to convert a time info I reveive as a UTC string to a timestamp using std::mktime in C++. My problem is that in <ctime> / <time.h> there is no function to convert to UTC; mktime will only return the timestamp as local time.

So I need to figure out the timezone offset and take it into account, but I can't find a platform-independent way that doesn't involve porting the whole code to boost::date_time. Is there some easy solution which I have overlooked?

Best Solution

timestamp = mktime(&tm) - _timezone;

or platform independent way:

 timestamp = mktime(&tm) - timezone;

If you look in the source of mktime() on line 00117, the time is converted to local time:

seconds += _timezone;