您可以使用strptime(3)解析时间,然后mktime(3)将其转换为time_t:const char *time_details = "16:35:12";struct tm tm;strptime(time_details, "%H:%M:%S", &tm);time_t t = mktime(&tm); // t is now your desired time_t
使用C ++ 11,您现在可以执行struct std::tm tm;std::istringstream ss("16:35:12");ss >> std::get_time(&tm, "%H:%M:%S"); // or just %T in this casestd::time_t time = mktime(&tm);请参阅std :: get_time和strftime以供参考