C++ Converting A String to a time_t variable
<p>I'm working on a C++ function that is supposed to figure out if a specified event happened between two time points. The event name, start datetime, and end datetime are all passed in from Lua as strings. Because of that, I need to parse my datetime strings into time_t variables. Based on what I've seen on StackOverflow and other forums, this code should work:</p>

<pre><code>time_t tStart;
int yy, month, dd, hh, mm, ss;
struct tm whenStart = {0};
const char *zStart = startTime.c_str();

sscanf(zStart, "%d/%d/%d %d:%d:%d", &amp;yy, &amp;month, &amp;dd, &amp;hh, &amp;mm, &amp;ss);
whenStart.tm_year = yy - 1900;
whenStart.tm_mon = month - 1;
whenStart.tm_mday = dd;
whenStart.tm_hour = hh;
whenStart.tm_min = mm;
whenStart.tm_sec = ss;
whenStart.tm_isdst = -1;

tStart = mktime(&amp;whenStart);
</code></pre>

<p>However, tStart appears to be assigned the value of -1 here. If I use strftime to reconstruct a string from whenStart, that tm structure appears to have been made completely correctly. Somehow mktime() is not liking the structure, I think. What is wrong with this code?</p>

<p>Also, before you answer, know that I already tried using a strptime() call. For reasons that are unclear to me, this function gets rejected with an "undefined reference to 'strptime'" error. The <a href="http://linux.die.net/man/3/strptime" rel="nofollow noreferrer">various</a> <a href="https://stackoverflow.com/questions/35234152/strptime-giving-implicit-declaration-and-undefined-reference">descriptions</a> <a href="https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rtref/strpti.htm" rel="nofollow noreferrer">I've</a> <a href="https://stackoverflow.com/questions/9403015/given-a-date-time-as-a-string-what-is-the-best-way-to-know-if-it-was-dst-at-tha">found</a> for how to fix this problem only serve to destroy the rest of the code base I'm working with, so I would rather avoid messing with _XOPEN_SOURCE or similar redefinitions.</p>

<p>Thanks for your help!</p>