I'm trying to convert a time info I receive 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?
mktime assumes that the date value is in the local time zone. Thus you can change the timezone environment variable beforehand (setenv) and get the UTC timezone.
Can also try looking at various home-made utc-mktimes, mktime-utcs, etc.