There is a line like Wed, 10 Oct 2018 01:15:33 GMT

What function can convert it to time_t value

  • 3
    Written by yourself ... - Harry

1 answer 1

Unix way

 const char *time_details = "16:35:12"; struct tm tm; strptime(time_details, "%H:%M:%S", &tm); time_t t = mktime(&tm); 

Windows way

 std::string startTime = "2016/05/18 13:10:00"; time_t tStart; int yy, month, dd, hh, mm, ss; struct tm whenStart; const char *zStart = startTime.c_str(); sscanf(zStart, "%d/%d/%d %d:%d:%d", &yy, &month, &dd, &hh, &mm, &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(&whenStart); std::cout << tStart << std::endl;