I\'m trying to convert a date string to a time_t
, but mktime() is returning seemingly random dates:
string datetime = \"2014-12-10 10:30\";
stru
You need to properly zero-initialize all of the other fields of the struct tm
instance before calling strptime()
, since it doesn't necessarily initialize every field. From the strptime() POSIX specification:
It is unspecified whether multiple calls to strptime() using the same tm structure will update the current contents of the structure or overwrite all contents of the structure. Conforming applications should make a single call to strptime() with a format and all data needed to completely specify the date and time being converted.
For example, this should suffice:
struct tm tmInfo = {0};