tm是一个结构,
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
}
你可以通过调用一些接口把time_t的秒数转化为tm更为直观的结构/
string和time_t类型转换
time_t startTime;
struct tm sourcedate;
memset(&sourcedate,0,sizeof(sourcedate));
sourcedate.tm_sec = atoi(stime.substr(12,2).c_str());
sourcedate.tm_min = atoi(stime.substr(10,2).c_str());;
sourcedate.tm_hour = atoi(stime.substr(8,2).c_str());
sourcedate.tm_mday = atoi(stime.substr(6,2).c_str());
sourcedate.tm_mon = atoi(stime.substr(4,2).c_str()) - 1;
sourcedate.tm_year = atoi(stime.substr(0,4).c_str()) - 1900;
startTime = mktime(&sourcedate);