I'm having much trouble converting a GMT time to a unix EPOCH time.
The problem seems to relate to mktime. My current timezone is +13 hrs ahead. I think this is the issue, mktime assumes localtime and when it calculates an epoch is returning a value that is about 12hrs before what the real GMT time is.
Here is my code.
time_t t;
struct tm tm;
strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm);
tm.tm_isdst = -1; // -1 tells mktime figure it out
t = mktime(&tm);
When s = "2018-01-19T03:35:12Z", it's computing the epoch to be 1516286112 Instead of an epoch which should be about 12hrs ahead.
On a system where the BIOS clock is set to GMT, this error does not occur. So I can only conclude that mktime is working as expected when that situation is true.
Incidentally, the string is coming from a nosql server which is displaying the correct time on a document. I'm grabbing the current epoch and comparing it to the parsed date from the document and computing the difference. This is where it all goes haywire!