How to convert a string variable containing time to time_t type in c++?

The Solution to How to convert a string variable containing time to time_t type in c++? is


With C++11 you can now do

struct std::tm tm;
std::istringstream ss("16:35:12");
ss >> std::get_time(&tm, "%H:%M:%S"); // or just %T in this case
std::time_t time = mktime(&tm);

see std::get_time and strftime for reference

~ Answered on 2014-07-30 12:37:57


Most Viewed Questions: