c++ - Getting time difference using a time_t converted from a string -


i trying diff between 2 dates. 1 date being right , other date converted time_t string representation of date.

my code follows

    const char *time_details = "12/03/2014";     struct tm tm;     strptime(time_details, "%m/%d/%y", &tm);     time_t mytime = mktime(&tm);      time_t now;     time(&now);     double seconds = difftime(now, mytime);      logg("now = %d", now);      logg("mytime = %d", mytime);     logg("unsigned int mytime = %d", (int)mytime); 

my output looks so:

now = 1417830679 mytime = -1 seconds = 1610001720 

mytime comes out -1 and, value seconds not correct either.

add before use (and might want pick different name variable)

memset(&tm, 0, sizeof(struct tm)); 

see notes section in strptime(3)


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -