最近写项目代码,需要将字符串时间转化成time_t类型,查找时间函数库与格式化函数,总结如下:
char *p_time = "2013-07-04 15:04:23";
struct tm tm_time;
sscanf(p_time , "%4d-%2d-%2d %2d:%2d:%2d", &tm_time.tm_year, &tm_time.tm_mon, &tm_time.tm_mday,
&tm_time.tm_hour, &tm_time.tm_min, &tm_time.tm_sec);
time_t time = mktime(&tm_time);
这样就完全转换过来了。