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
Post a Comment